Under the hood
@ryfylke-react/toast
is built using CustomEvent
.
When you initialize the library using initToast
, these things happen:
- We generate a random event-type with a hardcoded prefix.
- We configure
toast
,useToasts
,ToastProvider
andsubscribeToToasts
to post to and listen to this event-type (or "channel"). - We apply the generic types supplied by the user to the utils.
- We return the utils to the user.
useToasts
utilizessubscribeToToasts
internally with auseEffect
and some state.ToastProvider
utilizesuseToasts
internally, and exposes some props to help the user render the toast-list.
Really it all boils down subscribing to CustomEvent
s and exposing some helpers to the user. useToasts
is just some sugar on top of subscribeToToasts
, and ToastProvider
is just some sugar on top of useToasts
.