M
M
Maxim2020-04-26 12:53:48
React
Maxim, 2020-04-26 12:53:48

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

2 answer(s)
R
Robur, 2020-04-26
@Maksum77

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

V
Vladimir Proskurin, 2020-04-26
@Vlad_IT

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 question

Ask a Question

731 491 924 answers to any question