Does a React.memo memoized component compare props with the previous component instance/invocation of the component or with the same component instance from the previous render cycle? Or, in other words, where does prevProps in the comparison function come from?
React.memo: which component instance is used for comparison as previous props?
19 views Asked by zhulien At
1
Each instance of
React.memomemoized component compares props with the same instance from the previous render cycle.Having the following example:
We get:
Beware: various AI models get this wrong and state that
prevPropscomes from the previous invocation of the component in the same rendering cycle or in other words -items[1]will be compared toitems[0]which is false.