Open micah-redwood opened 1 year ago
Hi, as far as I understand your question correctly – you need a separate component to know when a specific toast is in the DOM. Looking at the API, the way I would do this is by:
useToast()
hook.ref
to the component.ref
to see if the component is in the DOM currently by adding it to some sort of global context.Hope this helps.
Hi, first off thanks for maintaining this really nifty, well-designed library!
I recently ran into a use case where some code outside of a React component needed to know if a particular toast was visible.
AFAIK the only way to access all the toasts' state is via the
useToasterStore
hook, so to expose the list of visible toast IDs to the outside, I had to manually render a component and expose it's state via a wrapping Promise:I do not love this solution for many reasons, and today discovered that occasionally it takes over 10ms for this render to happen, slowing down my app.
Any chance we could expose the return value of
useToasterStore
or allow registering a custom listener? Really any way of accessing this data without having to trigger a React function component render.Thanks!