Answer the question
In order to leave comments, you need to log in
How to write a react hook?
there is a component - a button, in one case, when we click, we call one handler (which is formed through react.useCallback), in the other case, we call the second handler (also formed through react.useCallback). But as we know, the sequence of hook calls cannot be changed in the rules, what to do?
Answer the question
In order to leave comments, you need to log in
And how does the call of handlers affect the call of hooks?
always call both hooks always, and you can call handlers as you like and in any order
Define the third useCallback, and conditionally call one of the callbacks in it. Well, or in the place where the callback is passed, pass it by condition.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question