react-modal
react-modal copied to clipboard
Possible to close modal from a child element?
Hi all, I have a use case where I need to be able to close the modal, but it should be invoked using a function somewhere, or a click event from a button which is one of the child elements. I can't seem to figure out how to accomplish this after Googling around.
Also, this modal is nested within another component, so there's no access to the state or props.
Hi all, I have a use case where I need to be able to close the modal, but it should be invoked using a function somewhere
Did you try passing the close handler from the modal to the child component and involve that handler in child components?
Also, this modal is nested within another component, so there's no access to the state or props.
You're able to pass these props down like -> parent component -> another component -> child component (where you'd like to use the parent state and call its close event handler)
I have implemented this solution https://stackoverflow.com/a/71464748/1770571 and it works properly