
Security News
Browserslist-rs Gets Major Refactor, Cutting Binary Size by Over 1MB
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
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 3 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
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Research
Security News
Eight new malicious Firefox extensions impersonate games, steal OAuth tokens, hijack sessions, and exploit browser permissions to spy on users.
Security News
The official Go SDK for the Model Context Protocol is in development, with a stable, production-ready release expected by August 2025.