Blogger Information
Blog 47
fans 0
comment 2
visits 102524
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
React Hooks深入-useEffect,usecallback,useMemo区别
拾一枝樱花的博客
Original
841 people have browsed it

useEffect

useEffect有两个参数,第一个参数是回调函数,第二个参数是一个数组,这个数组接受当前函数中的state,若第二个参数状态变化时,则执行回调函数;

useEffect只对当前函数中的状态更新有效;

useCallback

父组件将一个方法传递给子组件,若父组件的其他状态发生变化时,子组件也会跟着渲染多次,会造成性能浪费;
usecallback是将父组件传给子组件的方法给缓存下来,只有当 usecallback中的第二个参数状态变化时,子组件才重新渲染;

useMemo

父组件将一个值传递给子组件,若父组件的其他值发生变化时,子组件也会跟着渲染多次,会造成性能浪费;
useMemo是将父组件传递给子组件的值缓存起来,只有当 useMemo中的第二个参数状态变化时,子组件才重新渲染;

Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post