1
1
12332112021-06-09 13:12:14
React
1233211, 2021-06-09 13:12:14

How to properly use useCallback and a function wrapped in memo?

It is clear that we must wrap the function in useCallback if we want to pass it to the inner component wrapped in memo. But what if I want to pass the "setIsOpen" function from useState to the inner component? Can it just be passed around or does it need to be wrapped as well?
const [isOpen, setIsOpen] = useState(false);

Answer the question

In order to leave comments, you need to log in

2 answer(s)
0
0xD34F, 2021-06-09
@1233211

I wonder what the documentation has to say about the state update function? Yes, here's what :

React ensures that the function identity is setStatestable and doesn't change across re-renders.

You don't need to wrap anything.

D
Dmitry Markov, 2021-06-09
@En-Tilza

you can just pass it to props

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question