Replies: 1 comment
-
I also don't fully understand when a re-render is triggered. I use
And I validated with useSWRConfig() that the cache is used and filled before the But still for some reason it causes 1 more render than required. isValidating always stays false.
I couldn't use fallbackData because that seems to have some odd behaviours with revalidation. Then It wouldn't correctly fetch data when the key was changed. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
The docs mention deep comparison should prevent unnecessary re-renders here https://swr.vercel.app/docs/advanced/performance#deep-comparison
However, I am getting re-renders using code very similar to the next.js example here https://swr.vercel.app/docs/with-nextjs
When I log out
data
in the Article component the data does not change but it is output twice indicating that there was a re-render.What is causing this to happen? It seems data should only be output once since it did not change.
I even mocked my fetcher to return like this and the problem still happens
Edit:
here is an example forked from the Next.js SSR example here https://swr.vercel.app/examples/ssr:
https://codesandbox.io/s/elastic-resonance-kyxkp
The only update I made was to change
const { data, error } = useSWR(API);
toconst { data, error } = useSWR(API, fetcher);
This causes
Is data ready? true
to log twiceBeta Was this translation helpful? Give feedback.
All reactions