Compare array with useMemo
Answered
Puli posted this in #help-forum
PuliOP
In the example code from the React official website, why can they use arrays as dependencies for
[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)
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
2 Replies
@Puli 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)
Because they are passed from props. It is gonna re-render if the props change
Answer
@Ray Because they are passed from props. It is gonna re-render if the props change
PuliOP
ohhh I finally got it, thank you