Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Cache not working with Next.js #296

Open
gabsn opened this issue Oct 13, 2020 · 1 comment
Open

Cache not working with Next.js #296

gabsn opened this issue Oct 13, 2020 · 1 comment

Comments

@gabsn
Copy link

gabsn commented Oct 13, 2020

Getting the error There is no persistent storage on the Server currently when using useFetch with persist: true in a Next.js app:

  const { loading, data } = useFetch("/api/ip", { persist: true }, []);

This is due to the use of useSSR here:

const { isNative, isServer } = useSSR()

which return isServer: true and therefore throw an error.

The problem is that in the context of Next.js we need to wait for component mount before being able to use a global browser variable (See this thread for more details)

So here comes the paradox:

  • we need to wait for component to mount before calling useFetch(url, { persist: true }, [])
  • we need to call the hook at every render and cannot wait for some conditions to be fulfilled

A potential solution might be to make the check on isServer optional for Next.js users.

@iamthesiz
Copy link
Collaborator

Will respond. Need time to think. Bare with me.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants