You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The user fires notifications before the UI is mounted or after it’s unmounted. Should it error? or queue? Should it time out?
How do we solve the problem
API
We maintain API parity for the existing solution but manage the state outside of react. a Global api to create a notifications instance that includes open / close methods, and a provider that must be rendered by the user. The user can create their own instance, or use a global one we also provide.
interfaceNotificationsApi{// Original methodsopen(...)close(...)Provider: React.ComponentType<{}>}// Allow users creating their own instanceexportfunctioncreateNotifications(options): NotificationsApi;// Provide global default instanceconst{ open, close, Provider }=createNotifications()export{open,close,Provider}// backwards compatibilityexportfunctionuseNotifications(){return{ open, close }}
User can then use it in their zustand store as such:
import{create}from'zustand'import*asnotificationsfrom'@toolpad/core/notifications'constuseStore=create((set)=>({bears: 0,increasePopulation: ()=>{set((state)=>({bears: state.bears+1}))notifications.show('One more bear',{})},removeAllBears: ()=>set({bears: 0}),updateBears: (newBears)=>set({bears: newBears}),}))
Edge-case
When no UI is rendered, notifications are queued. As soon as UI is rendered queued notifications are shown. It’s the responsibility of the user to have the provider rendered. If it turns out problematic we can consider adding a warning in dev if we detect:
The UI has unmounted and notifications are enqueue
The UI has never mounted and notifications have been enqueued for longer than X milliseconds.
Which problem do we want to solve
How do we solve the problem
API
We maintain API parity for the existing solution but manage the state outside of react. a Global api to create a notifications instance that includes
open
/close
methods, and a provider that must be rendered by the user. The user can create their own instance, or use a global one we also provide.User can then use it in their zustand store as such:
Edge-case
When no UI is rendered, notifications are queued. As soon as UI is rendered queued notifications are shown. It’s the responsibility of the user to have the provider rendered. If it turns out problematic we can consider adding a warning in dev if we detect:
but let's await user feedback first.
Implementation
#4628
The text was updated successfully, but these errors were encountered: