How to use react toastify to show a promise toast when using a mutation in trpc?
I'm trying to show a promise toast but cant figure out how to do it. Can someone please help.
Thanks
16 Replies
Use the onSuccess to trigger the toast
@Neto there is no onSuccess, but there is isSuccess. But if I have understood it correctly, I need a Promise to be returned to trigger a promise toast. but isSuccess is boolean
onSuccess: (data: TData) => void
Optional
This function will fire any time the query successfully fetches new data.
useContext | tRPC
useContext is a hook that gives you access to helpers that let you manage the cached data of the queries you execute via @trpc/react-query. These helpers are actually thin wrappers around @tanstack/react-query's queryClient methods. If you want more in-depth information about options and usage patterns for useContext helpers than what we provide...
like this
thanks man
just that you wont use the context part, only using it to trigger the toast
but im still confused how you do this inside that function.
what toast lib are you using?
react-toastify
you can ignore the promise part
if you really want to add a delay on the toast
you can just paste the code inside the onSuccess
same effect
to be more elaborate, I'm fetching data from another API using this mutation. So I would need the loading toast till the data is sent to the client.
i guess I can do this like this,
you have another callback on the mutation
woah
cool man... lemme check it out