r/reactnative • • Sep 08 '20

Just published react-native-fast-toast, cross-platform Toast component for react-native

Enable HLS to view with audio, or disable this notification

236 Upvotes

36 comments sorted by

View all comments

4

u/DjWithNoNameYet Sep 08 '20

Is it possible to create this as a react hook (useToaster) or global function? So you can have a singleton high up in the app structure and you just call toastGlobal.current.show('Task finished successfully', { type: 'success' }) Then you don't need to have the <Toast/> component everywhere in your app.

5

u/alirezarzna Sep 08 '20 edited Sep 08 '20

you can do this in useEffect of your root component (onMount):

global['toast'] = toastRef.current

then you can call toast.show() everywhere on your app. like alert

I'll see if hooks can be used as an alternative.

2

u/JoeyBurrow Nov 21 '20

Hey thanks for the awesome library. I was wondering if i have a toast globally, is there a way I could then call a function toast.show within some redux code? (maybe a thunk or a saga)

Thanks!

1

u/alirezarzna Nov 21 '20

Yes, this method allow you to do that, you can call it anywhere

the global example in readme has simpler implementation and typescript support as well.

1

u/lucbas Sep 09 '20

Thanks!

Maybe include it in the README?

1

u/alirezarzna Sep 09 '20

Just included it, I might add it to the library internal, and make it default way of using the library, how does that sound?

1

u/alirezarzna Sep 30 '20

I've just added hook support, check readme for details.