How do I make useSWRInfinite work with global fallback #2164
Unanswered
andreiv-shap
asked this question in
Q&A
Replies: 1 comment 3 replies
-
@andreiv-shap import { unstable_serialize } from "swr/infinite";
<SWRConfig
value={{
fallback: {
[unstable_serialize(page => `https://api.github.com/repos/reactjs/react-a11y/issues?per_page=6&page=${page + 1}`)]: initialData
}
}}
>
<App />
</SWRConfig> |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi there!
I'm trying to use
useSWRInfinite
in a NextJS app. There I'm loading some data on the server, that I put inside the global config. The data is correctly picked up byuseSWR
but I'm not able to use it withuseSWRInfinite
. Setting the data infallbackData
, inside the hook call works, but I want to have a central place for setting up the prefetched/SSR data.Here's an example built on the example found in the docs: https://codesandbox.io/s/swr-infinite-forked-6hbfsl.
I am adding some dummy data and putting it in the
fallback
of the global config:To take advantage of this data and not automatically revalidate, I'm turning of some revalidation options on the
useSWRInfinite
call (this also helps visualise the issue):Wha I see is that the data provided in the global
fallback
is not loaded/used byuseSWRInfinite
. If I changeuseSWRInfinite
withuseSWR
(and change the key function, of course, with the corresponding string for the first page), the data in the globalfallback
is correctly used/displayed.What am I missing here? What am I doing wrong and how should I go about using SS fetched data set on the global
fallback
when usinguseSWRInfinite
?(The codesandbox example is using 2.0..0-beta-7 but it behaves the same even on 1.3.0)
Beta Was this translation helpful? Give feedback.
All reactions