Skip to content

Beautiful example of how keepPreviousData works nicely in React Query with Suspense, the same is not true for SWR

Notifications You must be signed in to change notification settings

WagnerMoreira/react-query-keep-prev-data

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

react-query-keep-prev-data

To run the json-server mock API

json-server --watch db.json --port 3004 --delay 2000

To run the React app

yarn then yarn run dev

There is another branch that shows how swr doesn't support keepPreviousData when suspense is enabled, switch to swr-version to see that. The same happens if you try to use a middleware, the problem comes from the fact that when using suspense, swr.data is always defined because it always gets the result from the request assigned to it, swr skips the step where swr.data is undefined when you use suspense, therefore keepPreviousData and any middleware that tries to achieve the same will also fail because those rely on swr.data being undefined.

About

Beautiful example of how keepPreviousData works nicely in React Query with Suspense, the same is not true for SWR

Topics

Resources

Stars

Watchers

Forks