通过在 React 中使用useMemo/ hook,有时我会发现/返回值useCallback导致的许多意外渲染。useMemouseCallback
当我React.memo用来减少 React 函数组件无用的渲染时,通过React.memo第二个参数,我可以控制比较。另外,我可以得到哪个道具导致当前渲染。就像之后:
const MemoComponent = React.memo((props) => {}, (prevProps, nextProps) => {
for (const key in prevProps) {
const prevValue = prevProps[key];
const nextValue = nextProps[key];
if (prevValue !== nextValue) {
return false; // form here I can get which cause render
}
}
return true;
})
我可以像以前一样获得哪个依赖原因useCallback/useMemo重新计算或 React devtools 吗?