How to have a globally accessible modal popup
Unanswered
Bombay posted this in #help-forum
BombayOP
Relatively new to nextjs, essentially lets say I have a Confirm modal component with props (title, message, confirmCallback, cancelCallback)
And from anywhere in my app I want to be able to call "openConfirmModal(options)"
Where options includes a method callback eg.
onConfirm: () => { //do stuff }
But I don't want to have to keep re-defining the modal component and mapped properties all over the place whenever i want the user to confirm something.
I'm coming from angular where I would separate this out into a service and call a dynamic modal method passing in the modal component.
I attempted this semi-angular style approach in nextjs and ended up having lots of issues, what would the correct approach be for this in nextjs? If it helps I am also using DaisyUI.
Thank you!
And from anywhere in my app I want to be able to call "openConfirmModal(options)"
Where options includes a method callback eg.
onConfirm: () => { //do stuff }
But I don't want to have to keep re-defining the modal component and mapped properties all over the place whenever i want the user to confirm something.
I'm coming from angular where I would separate this out into a service and call a dynamic modal method passing in the modal component.
I attempted this semi-angular style approach in nextjs and ended up having lots of issues, what would the correct approach be for this in nextjs? If it helps I am also using DaisyUI.
Thank you!
2 Replies
Sounds like toasts. I think you can copy a toast implementation (shadcn toasts for example), then tweak it a bit to become a modal
react-hot-toast is another good alternative that I think you can make it work