Security News
UK Officials Consider Banning Ransomware Payments from Public Entities
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.
react-use-modals
Advanced tools
Adds HTML Dialog capabilities as custom hooks
Statements | Branches | Functions | Lines |
---|---|---|---|
npm install --save react-use-modals
import React from 'react';
import useModals from 'react-use-modals';
const MyComponent = () => {
const { modalRef, isOpen, openModal, closeModal } = useModals();
return (
<>
<button onClick={openModal}>Open Modal</button>
<dialog ref={modalRef}>
<p>Modal Content</p>
<button onClick={closeModal}>Close Modal</button>
</dialog>
<p>Modal is {isOpen ? 'open' : 'closed'}</p>
</>
);
};
useModals
.import React from 'react';
import useModals from 'react-use-modals';
const MyComponent = () => {
const [modalRef, isOpen, openModal, closeModal] = useModals({
preventCloseOnEscape: true,
});
const [modalRef2, isOpen2, openModal2, closeModal2] = useModals({
closeOnBackdropClick: true,
onCloseCallback: (modalId) =>
console.log(`modal with id: ${modalId} closed!`),
});
return (
<>
<button onClick={openModal}>Open Modal</button>
<dialog ref={modalRef}>
<p>Modal Content</p>
<button onClick={closeModal}>Close Modal</button>
</dialog>
<p>Modal is {isOpen ? 'open' : 'closed'}</p>
<br />
<br />
<br />
<button onClick={openModal2}>Open Modal2</button>
<dialog ref={modalRef2} id="modal-id-2">
<p>Modal2 Content</p>
<button onClick={closeModal2}>Close Modal2</button>
</dialog>
<p>Modal2 is {isOpen2 ? 'open' : 'closed'}</p>
</>
);
};
useModals()
accepts the following options:
key | description | arguments | example |
---|---|---|---|
closeOnBackdropClick | Boolean controlling closing on backdrop click | N/A | N/A |
preventCloseOnEscape | Boolean controlling closing on escape key click | N/A | N/A |
onCloseCallback | Function callback run when closing. Receives modal id if available | modalId?: string | (modalId) => console.log(`modal with id: ${modalId} closed!`) |
And useModals()
returns:
key | description | arguments | example |
---|---|---|---|
isOpen | Boolean stating state of open or closed | N/A | N/A |
modalRef | HTMLDialogElement ref | N/A | N/A |
openModal | Function to open modal | N/A | N/A |
closeModal | Function to open modal | N/A | N/A |
dialog::backdrop {
background: rgba(255, 0, 0, 0.25);
}
Thanks goes to these wonderful people (emoji key):
Olavo Parno 🤔 💻 ⚠️ |
This project follows the all-contributors specification. Contributions of any kind welcome!
react-use-modals is MIT licensed.
This hook is created using create-react-hook.
FAQs
Adds HTML Dialog capabilities as custom hooks
The npm package react-use-modals receives a total of 0 weekly downloads. As such, react-use-modals popularity was classified as not popular.
We found that react-use-modals demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.
Security News
Snyk's use of malicious npm packages for research raises ethical concerns, highlighting risks in public deployment, data exfiltration, and unauthorized testing.
Research
Security News
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.