-
Hi, i use keepPreviousData and it works fine inside one route, but when switching to another, the data is lost. /user/:slug /user/1 -> /user/2 work fine /user/1 -> /category/5 lost previous data how can this be solved? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
If you change the route and render a completely different component, you'll get a new observer, so there is not previous data to keep. You would need to re-render the same component on a route change to achieve that. |
Beta Was this translation helpful? Give feedback.
keepPreviousData
works on a per-observer basis. Meaning if you have one call ofuseQuery
, and you render the same component again and the key changes, it will keep the data it had before.If you change the route and render a completely different component, you'll get a new observer, so there is not previous data to keep. You would need to re-render the same component on a route change to achieve that.