rt2zz / redux-persist

persist and rehydrate a redux store
MIT License
12.91k stars 863 forks source link

There are problems with RTK-Query support #1334

Open kuangshp opened 2 years ago

kuangshp commented 2 years ago

My project is using RTK-Query to request interface data, which will be stored in local storage by default, but I want the data stored in local storage to be only the data returned by the backend when I send Ajax requests, rather than including :queries, Mutations, provided and so on, and even getAccountList(undefined)。Online Demo Address

image

arthedza commented 2 years ago

@phryneas Do you have any updates on this?

phryneas commented 2 years ago

@arthedza Redux-persist is now supported by RTK-Query: https://redux-toolkit.js.org/rtk-query/usage/persistence-and-rehydration#redux-persist

With the big caveat that generally we recommend not to store api data in redux-persist: if the user presses F5 they expect to get new data, not cached data. Most of the time the RTK Query slice should just be blacklisted and not persisted at all. The internet works by fetching data from a server.

But regarding to this specific issue: that is the data that RTK Query needs. It is not meant to be beautiful to human eye. It looks like this, it will continue looking like this.

arthedza commented 2 years ago

@arthedza Redux-persist is now supported by RTK-Query: https://redux-toolkit.js.org/rtk-query/usage/persistence-and-rehydration#redux-persist

With the big caveat that generally we recommend not to store api data in redux-persist: if the user presses F5 they expect to get new data, not cached data. Most of the time the RTK Query slice should just be blacklisted and not persisted at all. The internet works by fetching data from a server.

But regarding to this specific issue: that is the data that RTK Query needs. It is not meant to be beautiful to human eye. It looks like this, it will continue looking like this.

Thank you for your quick response! What about using RTK-Query + redux-persist in a react-native environment when the internet connection is poor or temporarily absent? Would this approach be acceptable or should I look for another solution?

phryneas commented 2 years ago

I said generally. If you find a good reason to do it, do it. That's why we added the support.

mahfuz0498 commented 2 years ago

How can one persist the the result of an rtk query api for a long time ? when page is refreshed , the fetch request goes to server to fetch the request ? How to persist with rtk query ?

phryneas commented 2 years ago

@mahfuz0498 the documentation up there is not working for you? Can you provide a reproduction?