I have below function
const handleClick = React.useCallback(
(value) => {
dispatch({ value });
},
[dispatch]
);
My question is, in my case, is it necessary to have useCallback
? how React determines if the dependency is changed when the dependency is a function?
It is not necessary to use useCallback
but using that will reflect in good performance.
useCallback
returns a memoized callback. According to my understanding, react
invokes the function and only execute the callback function if there is any change in the dependencies that we have passed to it.
References:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.