pradel / react-responsive-modal

Simple responsive react modal
https://react-responsive-modal.leopradel.com/
MIT License
604 stars 95 forks source link

Multiple Modals On One Screen #481

Closed chusyntax closed 2 years ago

chusyntax commented 2 years ago

I am trying to have multiple modal buttons on one page and when I click on a different modal, it displays its own unique modal.

I tried this by changing the names of the state variables but that didn't work, it actually only opened up the first modal.

Here is a snippet of the code:

`const Projects = () => {

const [open, setOpen] = useState(false); const [open2, setOpen2] = useState(false);

const onOpenModal = () => setOpen(true); const onCloseModal = () => setOpen(false);

const onOpenModal2 = () => setOpen(true); const onCloseModal2 = () => setOpen2(false);

return (

Simple centered modal 1

Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam pulvinar risus non risus hendrerit venenatis. Pellentesque sit amet hendrerit risus, sed porttitor quam.

Simple centered modal 2

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam pulvinar risus non risus hendrerit venenatis. Pellentesque sit amet hendrerit risus, sed porttitor quam.

); };

export default Projects`

pradel commented 2 years ago

you have to replace const onOpenModal2 = () => setOpen(true); by const onOpenModal2 = () => setOpen2(true);

chusyntax commented 2 years ago

Yes that worked. Thank you!