-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
put initialData in cache #237
Labels
feature request
New feature or request
Comments
somewhat related to the goals in #158 |
This explains my issue here: #11 (comment) |
Merged
Workaround to cache the server-side initial data on the client side (as long as SWR doens't support it natively): https://www.npmjs.com/package/use-fetch-cache |
just use revalidateOnMount to trigger cache in backgrounnd |
Update for whoever comes to this issue: https://swr.vercel.app/docs/with-nextjs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
description
when populating a
useSWR
hook with initialData, that data is per-hook and not stored in the cache to be available to other hook invocations, resulting in duplicate fetches foruseSWR
invocations that don't have the SSR initialData passed to them.for example:
getInitialProps
function is generatinginitialData
as in the example.useSWR(someKey, { initialData })
and correctly SSR renders the initialData.useSWR(someKey)
. the child component'suseSWR
sees an empty cache and executes fetcher, resulting in an unnecessary fetch.workarounds
useSWR
in the parent and prop-drill / context-pass the return value ofuseSWR
to components that need itexpectation
when initialData is provided, it will be stored in the cache under the provided key. when other
useSWR
hooks are invoked, they'll see the cached value and avoid an extra call to fetcherThe text was updated successfully, but these errors were encountered: