Replies: 2 comments 8 replies
-
Personally, I don't see anything wrong with keeping the old content while fetching the new one. Of course, having a loader would be nice. I understand, though, that for some reason you don't want this behavior. Then I think I would probably do it the way you proposed. Alternatively, if using RTKQ, I would consider decreasing the value for |
Beta Was this translation helpful? Give feedback.
-
Urually this occurs because you think of your Redux store as "data for a component". If this data only exists for your component and resets when your component unmounts, it should probably be bound to your component as local state - or you step a moment back and think about your data. This is probable not You can structure your data by hand accordingly, or you can use RTK Query instead of manually fetching it, which I would recommend and which also stores data "by project" for you in such a case. It is covered in our official tutorial here: Essentials, Part 7: RTK Query Basics |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm using React, Redux Toolkit, and React Router.
When some pages load, data is fetched and placed in the store. If user leaves the page, and comes back to it, there's a flash of old content. The obvious solution is to reset the state for the relevant slice(s) when the user exits the page.
I'm guessing one way of going about this is to use
useEffect
when the page unmounts – something like this:I'm just wondering if there's a better way? Any advice gratefully received.
Beta Was this translation helpful? Give feedback.
All reactions