Skip to content

Best practice for isLoading. What different with isValidating? #563

Discussion options

You must be logged in to vote

Loading only happens once, when you don’t have data or error, this is when it’s the first time you use a key.

Validation can happen more than once, when you already have data or error and SWR is calling your fetcher again to update it.

I usually use Suspense for loading, but you can check if if you have data or error as in the examples (I like more the second one checking for error first and !data later).

You should use isValidating if you want to tell your users your data is being updated.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by terrierscript
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants