-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
React native query persist #4047
Description
Describe the bug
I have implemented the react-query persist configuration on a React Native project and persist the Auth data, then I realized sometimes the user has been being kicked out and I have put some debugging there, I'm using AsyncStorage and it works well, the cause of this behavior is react-query persist configuration, I don't know maybe some of those functions have a bug because I have followed up everything strictly based on documentations v4
My App.tsx:
import { QueryClientProvider } from '@tanstack/react-query';
import { queryClient, queryKeys } from '@helpers/query';
import AsyncStorage from '@react-native-async-storage/async-storage';
import { persistQueryClient } from '@tanstack/react-query-persist-client';
import { createAsyncStoragePersister } from '@tanstack/query-async-storage-persister';
import { SafeAreaProvider } from 'react-native-safe-area-context';
const asyncStoragePersistor = createAsyncStoragePersister({
storage: AsyncStorage,
key: queryKeys.loggedInUser,
});
persistQueryClient({
queryClient,
persister: asyncStoragePersistor,
});
const App = (): JSX.Element => {
return (
<QueryClientProvider client={queryClient}>
<SafeAreaProvider>
<RootStack />
<DropDownAlert />
</SafeAreaProvider>
</QueryClientProvider>
);
};Your minimal, reproducible example
https://github.com/amerllica/rq-persist-issue-reproduction
Steps to reproduce
- Implement React Native react-query persist configuration
- Add a console log in there to check the query data
- If you can see the data, re-load your app several times and you will see the query data will be empty
Expected behavior
After setting the query data, the react query must contain the app data always, in every reloading by any situation until I remove the data that is related to that key.
How often does this bug happen?
Sometimes
Screenshots or Videos
No response
Platform
- OS: macOS Monterey
- React Native
- 12.4
react-query version
4.2.1
TypeScript version
v4.4.4.
Additional context
"@tanstack/query-async-storage-persister": "^4.2.1",
"@tanstack/react-query": "^4.2.1",
"@tanstack/react-query-persist-client": "^4.2.1",
"@react-native-async-storage/async-storage": "~1.17.3"
And please do not use expo, I'm using bare React Native