-
Hi, I am doing CRUD on a list of entities. Say the current value is I delete This causes re-renders when looping through the array and rendering a component per object (the object has "changed" because React only does shallow comparisons). Am I right that the best way to solve this is to use React.memo e.g. this is not the responsibility of SWR?
Thanks very much! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
@rolznz But in your case, I think it's best to use If you don't want to re-render a component that uses |
Beta Was this translation helpful? Give feedback.
@rolznz
SWR has a compare option to customize a comparison function to avoid unnecessary re-renders by
useSWR
.https://swr.vercel.app/docs/options#options
But in your case, I think it's best to use
React.memo
to solve it because it's a matter of each element, so the compare option wouldn't help the case.If you don't want to re-render a component that uses
useSWR
, the compare option might be your help.