
Product
Introducing Webhook Events for Alert Changes
Add real-time Socket webhook events to your workflows to automatically receive software supply chain alert changes in real time.
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.

Product
Add real-time Socket webhook events to your workflows to automatically receive software supply chain alert changes in real time.

Security News
ENISA has become a CVE Program Root, giving the EU a central authority for coordinating vulnerability reporting, disclosure, and cross-border response.

Product
Socket now scans OpenVSX extensions, giving teams early detection of risky behaviors, hidden capabilities, and supply chain threats in developer tools.