Best practice for isLoading. What different with isValidating? #563
-
In SWR documentation, I cannot found about This page show like this
Similirary, [quick start] section show like this if (error) return <div>failed to load</div>
if (!data) return <div>loading...</div> And
Question1: What is best practice for isLoading? Is this |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
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. |
Beta Was this translation helpful? Give feedback.
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.