5 ms·
The snackbar problem is actually what redux is built to solve. You would "provide the toast()" function by having components dispatch a "toast" action. From the
by Sacho 10y ago
The snackbar problem is actually what redux is built to solve. You would "provide the toast()" function by having components dispatch a "toast" action. From there, your reducer would modify the snackbar state accordingly, e.g. by implementing a stack of toasts, and you would have a single global component render that state into popups.
- acemarke 10y agoYeah. There's a dozen existing "notifications with Redux" libs already: https://github.com/markerikson/redux-ecosystem-links/blob/master/widgets.md#notifications https://github.com/markerikson/redux-ecosystem-links/blob/ma... . Behavior-wise, it basically just amounts to a pair of SHOW and CLOSE actions, possibly with the reducer tracking an array of open notification entries, and a component that maps over the array and shows an actual notification entry. I glanced at the ones in my list, saw the similarities, and just wrote my own.
- platz 10y agoin other words, you don't call functions, you send messages.