I am making modal by referring to the link below with react hook.
How can I display a modal dialog in Redux that performs asynchronous actions?
The state of the modal is managed by Redux. I want to run some "function" when the modal is closed. However, this "function" should only work on a specific component, so when I open a modal in a specific component, I want to pass this "function" to the modal. But I'm not sure is it okay to pass and store the "function" to Redux. I did a lot of searches, but still I'm not sure.
I would really appreciate if someone would let me know if this is correct or not. Thanks for your reading.
SpecificComponent.jsx
const saySomthing = () => {
console.log("Now modal is close.");
}
const openModal = () => {
dispatch({
type: SHOW_MODAL,
modalProps: {
handleClose: saySomthing
})
}
Modal.jsx
const dispatch = useDispatch();
const modalProps = useSelctor((state) => state.modal.modalProps);
const handleClose = () => {
modalProps.handleClose();
dispatch({type: HIDE_MODAL});
}