DEV Community

Discussion on: The neatest way to handle alert dialogs in React 🥰

Collapse
 
devhammed profile image
Hammed Oyedele • Edited

Nice!!!

I have used this technique for 2 past React projects before ✌️✌️✌️

I used a global hook state manager that I created (github.com/devhammed/use-global-hook) then renders my custom Material UI Dialog component near routes in App.js then all I have to do is to call the showModal action (I use React.useReducer) whenever I need to:

showModal({
  title: "Hello",
  content: (<Typography>Hi</Typography>),
  actions: [] // buttons
})
Collapse
 
tabrez96 profile image
Tabrez Basha

Cool, can you share some examples for your implementation?

Collapse
 
devhammed profile image
Hammed Oyedele

The implementation is almost the same with the one in this post but I used use-global-hook instead of context (though it uses context under the hood too).

Collapse
 
dmtrkovalenko profile image
Dmitriy Kovalenko

Cool!