From fe735d5d26403e270807e761bb5af4c2a9deed58 Mon Sep 17 00:00:00 2001 From: a Date: Fri, 31 May 2024 17:15:02 +0200 Subject: [PATCH] lll --- App.js | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/App.js b/App.js index c9b1916..28de97e 100644 --- a/App.js +++ b/App.js @@ -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" })} /> - {query.data && query.data.toString() || ''} ); };