Next.js Discord

Discord Forum

Compare array with useMemo

Answered
Puli posted this in #help-forum
Open in Discord
PuliOP
In the example code from the React official website, why can they use arrays as dependencies for useMemo and React.memo? If it's using Object.is() to compare, why does that can skip some unnecessary re-renders?

[codesandbox link](https://codesandbox.io/p/sandbox/react-dev-forked-l8hcd3?file=/src/List.js:8,4)
[tutorial from React official website](https://react.dev/reference/react/useMemo#examples-recalculation)
Answered by Ray
Because they are passed from props. It is gonna re-render if the props change
View full answer

2 Replies