简体   繁体   中英

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

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 :/

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.

尝试将您的 Redux 状态保存在 localStorage

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM