[英]React hooks useCallback has dependency on function
I have below function我有以下功能
const handleClick = React.useCallback(
(value) => {
dispatch({ value });
},
[dispatch]
);
My question is, in my case, is it necessary to have useCallback
?我的问题是,就我而言,是否有必要使用
useCallback
? how React determines if the dependency is changed when the dependency is a function?当依赖是一个函数时,React 如何判断依赖是否改变?
It is not necessary to use useCallback
but using that will reflect in good performance.没有必要使用
useCallback
但使用它会反映良好的性能。
useCallback
returns a memoized callback. useCallback
返回一个记忆化的回调。 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.根据我的理解,
react
调用该函数,并且只有在我们传递给它的依赖项发生任何变化时才执行回调函数。
References:参考:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.