Replies: 1 comment
-
Ok first you need to add check for window !== undefined:
Put the then you need to make all the components calling useSWR() client rendering to avoid this error. In nextjs pages router you need to do:
in app router, you do 'use client' to make the component client component to use swr
|
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
-
Hi everyone,
I've been trying to implement a persistent cache using SWR in my Next.js app, following the example in the official documentation (https://swr.vercel.app/docs/advanced/cache#localstorage-based-persistent-cache). However, I'm running into a ReferenceError: localStorage is not defined error.
Can anyone provide guidance on how to fix this error and enable cache persistence between page reloads in Next.js? If possible, could you also provide a working example?
Thank you in advance!
Beta Was this translation helpful? Give feedback.
All reactions