Troubleshooting SWR Mutations and Rerendering #1001
-
UPDATE/TLDR: When updating arrays using MORE DETAIL: While using SWR, it seems that some mutations do not cause certain components to rerender when I expect them to. From a troubleshooting perspective, I've found it difficult to isolate whether the issue is that SWR is not triggering a rerender OR whether the component is not rerendering when it should (or I want it to 🙄 ). I often have issues triggering a rerender when mutating an array where only a property within an object in the array changes or when replacing an existing object in an array with an updated object. Below is an example of where I replace an existing object in an array and then call the mutation to update the data but the component does not rerender:
While doing some troubleshooting, if I remove an object from the array, a rerender is triggered. It seems I need to make more "substantial" changes to the array (like changing the length of it) to cause a rerender. My question: how can I better know if SWR is not triggering the change when I expect it to OR if the component is not rerendering despite SWR passing on the data changes? Is there anyway to log when SWR does its data comparison and decides that data has indeed changed? I'd be grateful for any tips related to troubleshooting rerender issues with SWR to help determine if the issue lies with my implementation of SWR or the component. For instance, if I just revalidate the data using |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi, from the doc (https://swr.vercel.app/docs/options), SWR uses
|
Beta Was this translation helpful? Give feedback.
Hi, from the doc (https://swr.vercel.app/docs/options), SWR uses
dequal
(https://github.com/lukeed/dequal) as a compare function in order to trigger a rerender or not.Seems like the following would trigger a rerender