How to use ToastState (useToastState) in side effects #7481
Replies: 2 comments
-
What's the thing that's driving the state change? Can you create the toast there? for instance, in a press handler? or a network request handler? I don't quite follow:
Could you have a conditional in the press handler to determine if you should show it again? Otherwise, the infinite loop is not hard to avoid, you can just track the previous value and compare to that before calling state.add again. |
Beta Was this translation helpful? Give feedback.
-
Hey, I've also run into the same problem in my app. Ok, I might agree with @snowystinger - once you know about the issue it is pretty easy to avoid, but since this is a public library, I think there's still value in fixing it, right? To me, the same way as for native |
Beta Was this translation helpful? Give feedback.
-
I implemented our own version of Toast using useToast and useToastState. As such, to create new toast we use
state.add()
but not in every case we want to call it on user interaction such as button press.How should we use it in, for example useEffect as a reaction to some other change in application, when we want to follow the "non-exhaustive deps" rule for the dependency array? When we add the
state
in the dependency array[state]
it creates infinite cycle.Any words of advice or something I am missing here?
Beta Was this translation helpful? Give feedback.
All reactions