multiple toast messages
Hello, anyone can review this code, and tell me why the toast.success is being rendered 4-5 times?
As you can see I am using query
1 Reply
robust-apricot•13mo ago
Copied from #query channel:
I'm not a pro but there are couple things that stand out to me:
The component seems to be that it has a lot of re-rendering going on. You have the two queries plus the modal states from the useModal hook. The re-rendering plus the useEffect having the dependency of just the isSuccess (venueIsSuccess) could be causing multiple truthy fires of the toast
Few things I would try based on what you are trying to accomplish:
Play around with the dependencies of the useEffect to include:
data (to make sure there is actual data from the query which can be checked in the hook)
isFetched (sometimes it helps to log these out to see when isSuccess is true and isFetched is true and if they are the same
In general it feels like you should refactor this component out into smaller components to get to the bottom of the issue. To have dependent queries like this that also have a useEffect depending on the end of this waterfall could be an issue. I could see the toast creation being it's own hook which checks to make sure there is a new venue to display before opening another toast and modal review. Especially because you are opening a modal on every new venue it seems like this could almost be a mutation call when a new payment comes through
Hope this helps!