Home > Blockchain >  How can I cache Redux states? (without redux-persist)
How can I cache Redux states? (without redux-persist)

Time:07-18

Problem

I want to save data in the store with Redux, like tokens and user-related data to be used across the whole application (I'm using React).

The problem is that Redux does not persist in the state when refreshing a page.

Thoughts

  • I'm not convinced about using redux-persist since the package doesn't seem very active.
  • I've seen RTK Query, but from what I'm understanding, I still have to make the API call to get the data (even if the actual call is not made and gets the cached data). Seems too much of an overkill.

Maybe I'm missing some core Redux or React concept? It feels a bit crazy for me not to be able to find a go-to package (or any other method) just to save a piece of data and be able to access it across the whole application without resetting on refresh :/

CodePudding user response:

try to save your Redux states in localStorage

CodePudding user response:

Redux-persist doesn't need to be very active - it works for half a decade now and there is just no need for a lot of changes. It works.

It is the to-go-package for that purpose.

  • Related