我想檢查某個 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已過時。
如何使用 React 內置的 React.memo 比較功能?
ITMISS
2022-11-11 16:18:58