This commit is contained in:
a 2024-05-31 17:15:02 +02:00
parent af59182923
commit fe735d5d26

19
App.js
View File

@ -17,14 +17,14 @@ import {
Button,
} from "react-native";
import { useNetInfoInstance } from "@react-native-community/netinfo";
import NetInfo from '@react-native-community/netinfo'
import {
useQuery,
useMutation,
useQueryClient,
QueryClient,
QueryClientProvider,
onlineManager
} from "@tanstack/react-query";
import { PersistQueryClientProvider } from "@tanstack/react-query-persist-client";
import { createAsyncStoragePersister } from "@tanstack/query-async-storage-persister";
@ -42,6 +42,15 @@ const queryClient = new QueryClient({
},
});
onlineManager.setEventListener((setOnline) => {
return NetInfo.addEventListener((state) => {
setOnline(!!state.isConnected)
if (state.isConnected)
queryClient.resumePausedMutations()
console.log(123)
})
})
const asyncStoragePersister = createAsyncStoragePersister({
storage: AsyncStorage,
});
@ -52,7 +61,8 @@ queryClient.setMutationDefaults(["addTodo"], {
mutationFn: ({ page }) => {
return makeCall(page);
},
retry: 3,
retry: Infinity,
networkMode: 'offline',
});
@ -90,7 +100,7 @@ function App() {
const ReqButton = () => {
const mutation = useMutation({ mutationKey: ["addTodo"] });
const query = useQuery({ queryKey: ["todos"], queryFn: () => makeCall("a") });
//const query = useQuery({ queryKey: ["todos"], queryFn: () => makeCall("a") });
return (
<>
@ -98,7 +108,6 @@ const ReqButton = () => {
title={"Request"}
onPress={() => mutation.mutate({ page: "a" })}
/>
<Text>{query.data && query.data.toString() || ''}</Text>
</>
);
};