T
TanStack3y ago
correct-apricot

Pausing Mutations when networkMode: "online"

Hello! I am working on a React Native app, attempting to persist paused mutations to async storage, using a default mutation fn and PersistQueryClientProvider. ReactQuery v4 My issue is my mutations immediately throw an error when my device is offline, even when my networkMode is set to "online". My assumption is because an error is thrown the mutation is never paused and never gets persisted. And when calling "queryClient.getMutationCache()", the mutations array is empty.
Any idea what could be going on? My default mutation fn: /////////////////////////////// queryClient.setMutationDefaults(leadKeys.create(), { mutationFn: postNewLead, onSuccess: (data) => { alert("MUTATE SUCCESS"); }, onError: (err) => { alert("MUTATE FAILURE"); }, networkMode: "online", }); /////////////////////////////// And used in my code... ////////////////////////////// const { mutate: submitLead, isLoading, isPaused } = useMutation({ mutationKey: ["createLead"] }); //////////////////////////////
1 Reply
correct-apricot
correct-apricotOP3y ago
It looks like my issue was I was not using the onlineManager to set the offline state from NetInfo's event listener. So React Query had no way to know I was offline or not

Did you find this page helpful?