我想检查某个 prop 是否手动更改,然后使用 React 的内置比较功能对其他 prop 进行比较。例如:
React.memo(
() => <div />,
(prevProps, nextProps) => {
if (!nextProps.visible) {
return true;
}
return React.shallowCompare(prevProps, nextProps);
},
);
我可以轻松编写自己的比较函数或从 React 的源代码复制/粘贴,但如果 React 更改了它们的默认比较函数,那么我也必须手动更改我的函数。有没有办法使用 React 的内置比较功能React.memo?
此外,AFAIKreact-addons-shallow-compare已过时。
慕工程0101907
相关分类