data is undefined when `fallbackData` and `revalidateOnMount: false` are provided
See original GitHub issueBug report
Description / Observed Behavior
if I provide both fallbackData
and revalidateOnMount: false
as options to useSWR, the initial data
that is returned is undefined and not fallbackData
. Before that could be done with initialData
property and for what I could understand of fallbackData
is that it would have the same behaviour.
const initialData = { id: 1 }
const { data, error, mutate } = useSWR('/api/templates', { fallbackData: initialData, revalidateOnMount: false });
console.log(data); // undefined
Expected Behavior
data
should assume the fallbackData
value.
Additional Context
SWR version: 1.0.0
BTW, I’m using nextjs and trying to SSR a page with some initial data, avoiding the initial fetch on mount.
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
How to make useSWR mutations with a given initial value?
I am using swr 1.2.2 version. Looks like after version 1.0 initialData is no longer exists. It replaced with fallbackData.
Read more >How to fix SWR to work correctly with initialData or fallbackData
I've been using the awesome data fetching library SWR (the same the same team behind Next.js, the React framework. SWR is a lightweight...
Read more >そうです。わたしがReactをシンプルにするSWRです。 - Zenn
'/api/user' : null, fetcher, { suspense: true }) // `data` will be `undefined` if `isReady` is false // ... } この制限に関する技術的な詳細が知り ...
Read more >swr - NPM Package Versions - Socket - Socket.dev
React Hooks library for remote data fetching. Version: 1.3.0 was published by quietshu. ... isArray(key) && key[0] === 'item', undefined, false ).
Read more >TypeScript - SWR
const { data, error } = useSWR<User, Error>(uid, fetcher); // `data` will ... SWRConfiguration = { fallbackData: "fallback", revalidateOnMount: false // .
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I can’t reproduce your problem. It seems works fine. FYI: https://stackblitz.com/edit/nextjs-qeugdv?file=pages%2Findex.js
And initialData only works before #1370
Good catch, thank you!