【发布时间】:2020-11-02 05:43:54
【问题描述】:
我想检查某个 prop 是否手动更改,然后使用 React 内置的比较功能对其他 prop 进行比较。例如:
React.memo(
() => <div />,
(prevProps, nextProps) => {
if (!nextProps.visible) {
return true;
}
return React.shallowCompare(prevProps, nextProps);
},
);
我可以轻松编写自己的比较函数或从 React 的源代码复制/粘贴,但如果 React 更改了它们的默认比较函数,那么我也必须手动更改我的函数。有没有办法为React.memo 使用 React 的内置比较功能?
另外,AFAIK,react-addons-shallow-compare 已经过时了。
【问题讨论】:
标签: javascript reactjs