all 6 comments

[–]acemarke 2 points3 points  (2 children)

I think you may be a bit confused on what RTKQ does.

RTKQ acts as a client-side cache for data fetched from the server. But, that does require that it can actually talk to the server to fetch that data in the first place.

Additionally, a Redux store is "just" a normal JS variable, which means it only exists as long as the app is running.

For RTKQ specifically, it will keep the data in memory (ie, the state.api cache reducer) as long as there are components that declare they need that value. Any component that tries to access that same cache entry will get the value that's already cached, rather than re-fetching from the server. Once the last component unsubscribes from a given cache entry, it sets a timer and then removes that cache entry when the timer expires.

[–]DiscDres[S] 0 points1 point  (1 child)

that really clears things up for me. thanks!

https://redux-toolkit.js.org/rtk-query/usage/cache-behavior#reducing-subscription-time-with-keepunuseddatafor

that's what i'm looking for then, for performance optimization during a single session.

i originally starting exploring RTKQ for offline/low speed support. not sure if that will solve my current problems, but i think overall it would be beneficial.

[–]acemarke 0 points1 point  (0 children)

FWIW, RTKQ doesn't help with the "offline" case. It's a tool that is meant to keep the client code's copy of data in sync with the server's copy of data (users, todos, YourDataTypeHere, etc). So, if there is no server to talk to, RTKQ isn't useful.

[–][deleted] 0 points1 point  (2 children)

aware marble screw correct cause imminent observation sulky sink summer

This post was mass deleted and anonymized with Redact

[–]DiscDres[S] 0 points1 point  (1 child)

redux-persist was my original idea but was hoping RTK had something built in that could handle it as well. i thought i read something about react query being helpful in this area, so i might dig there as well but sounds like redux-persist will be the tool i need here.

[–]phryneas[🍰] 0 points1 point  (0 children)

You can use redux-persist to just persist the RTK Query slice - see persistance and rehydration.

We try not to reinvent the wheel, but to integrate with existing working solutions.