question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

data is undefined when `fallbackData` and `revalidateOnMount: false` are provided

See original GitHub issue

Bug 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:closed
  • Created 2 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
promer94commented, Sep 1, 2021

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

1reaction
shudingcommented, Sep 1, 2021

Good catch, thank you!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found