Skip to content
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

isLoading always typed as false when using fallbackData #2866

Closed
EthicalJobsJesse opened this issue Jan 4, 2024 · 0 comments · Fixed by #2875
Closed

isLoading always typed as false when using fallbackData #2866

EthicalJobsJesse opened this issue Jan 4, 2024 · 0 comments · Fixed by #2875

Comments

@EthicalJobsJesse
Copy link

Bug report

Description / Observed Behavior

isLoading is typed as false when using fallbackData

Expected Behavior

image

According to https://swr.vercel.app/docs/advanced/understanding#fallback, when fallbackData is set it will still run the initial fetch, and sLoading will be true while that's happening. When checking the values for isLoading this is what happens. However the type doesn't match, meaning we currently need to disable linting checks or cast isLoading to a boolean.

Repro Steps / Code Example

const { data, isLoading } = useSWR('key', () => Promise.resolve([]), { fallbackData: [] });

Checking the type isLoading it will be reported as false rather that boolean. If you remove fallbackData the type will correctly be reported as boolean

Additional Context

SWR version: v2.2.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants