SWR first returns the data from cache (stale), then sends the fetch request (revalidate), and finally comes with the up-to-date data again.
Basically not showing "loading" screen as soon as a data is being fetched/refetched.
That sounds a bit like Pending → Skeleton → Complete Concurrent UI pattern in the experimental channel (but not sure if they are the same).
You can also do optimisitic UI update using mutate, meaning, you can show updated state right away before getting remote data. And revert if the change was not made.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
As I am also a noob at
useSWR
, I just tried to explain as much as I know :pYes. One would normally use
useEffect
by default to fetch data (as it's a side effect).useSWR
would ease the burden of having to write much boilterplate code.useSWR
is usinguseLayoutEffect
overuseEffect
(, which I'd like to know the reason behind it).github.com/zeit/swr/blob/a323fa702...
thinking out loudly:
Maybe this article by Dave Ceddia would provide an answer.
When to useLayoutEffect Instead of useEffect
It's only one of the nice features :)
The main benefit is hidden in the name, SWR
Basically not showing "loading" screen as soon as a data is being fetched/refetched.
That sounds a bit like Pending → Skeleton → Complete Concurrent UI pattern in the experimental channel (but not sure if they are the same).
You can also do optimisitic UI update using mutate, meaning, you can show updated state right away before getting remote data. And revert if the change was not made.