Conversation
| const old = state.toasts; | ||
| const i = old.findIndex(t => t.id === id); | ||
| const updatedToast = { ...old[i], ...options }; | ||
| const updatedToast = { ...old[i], ...omit(options, 'id') }; |
There was a problem hiding this comment.
These id changes fix some flow errors I was getting.
| super(props); | ||
|
|
||
| contexts[props.name] = contexts[props.name] || React.createContext(); | ||
| const context = contexts[props.name]; |
There was a problem hiding this comment.
We only create a new context if there isn't already one for that name.
Then we continue using the created context within this component for its lifetime.
| <Consumer>{context => children(context)}</Consumer> | ||
| ); | ||
| export const ToastConsumer = ({ | ||
| name = DEFAULT_CONTEXT_NAME, |
There was a problem hiding this comment.
Each of the 3 ways of consuming toast context (<ToastConsumer>, withToastManager(), and useToasts()) now all accept an optional name prop.
That name is used to lookup a context created by a provider.
If the named context isn't known, then an error is thrown. Otherwise, that named context is the one used for the life of the component.
In this way, any deeply nested consumers can connect to any parent provider no matter how many they are as long as they have unique names.
| | 'top-right'; | ||
|
|
||
| export type ToastType = Options & { appearance: AppearanceTypes, content: Node, id: Id }; | ||
| export type ToastType = { content: Node, id: Id } & Options; |
There was a problem hiding this comment.
This fixes a flow issue I was having where it thought id was optional on internal state.
|
I've published the changes in this PR as |
|
I have tested the PR by @jesstelford! It works like a charm thank you. Please merge! |
NOTE: PR best viewed with whitespace changes hidden
From the updated docs:
Displaying individual toasts differently is done using nested
<ToastProvider>s.For example, the docs page displays both "notification" style & "snack bar" style toasts simultaneously on the same page.
Nested Providers must be given a unique
nameprop, which is then also passed to the<ToastConsumer>component oruseToasts()hook.