fix : default mutation added
This commit is contained in:
parent
93e90eaf3f
commit
d34673a490
@ -5,31 +5,31 @@ import NetInfo from '@react-native-community/netinfo';
|
||||
import AsyncStorage from '@react-native-async-storage/async-storage';
|
||||
import useOfflineMutation from './useOfflineMutation';
|
||||
|
||||
const retryOfflineRequests = async (mutation) => {
|
||||
const pendingRequest = await AsyncStorage.getItem('pendingRequest');
|
||||
if (pendingRequest) {
|
||||
mutation.mutate(JSON.parse(pendingRequest));
|
||||
}
|
||||
};
|
||||
//const retryOfflineRequests = async (mutation) => {
|
||||
// const pendingRequest = await AsyncStorage.getItem('pendingRequest');
|
||||
// if (pendingRequest) {
|
||||
// mutation.mutate(JSON.parse(pendingRequest));
|
||||
// }
|
||||
//};
|
||||
|
||||
const MyComponent = () => {
|
||||
const mutation = useOfflineMutation();
|
||||
|
||||
// Retry pending requests on component mount
|
||||
useEffect(() => {
|
||||
retryOfflineRequests(mutation);
|
||||
|
||||
// Add event listener for when the app comes back online
|
||||
const unsubscribe = NetInfo.addEventListener(state => {
|
||||
if (state.isConnected) {
|
||||
retryOfflineRequests(mutation);
|
||||
}
|
||||
});
|
||||
|
||||
return () => {
|
||||
unsubscribe();
|
||||
};
|
||||
}, [mutation]);
|
||||
// useEffect(() => {
|
||||
// retryOfflineRequests(mutation);
|
||||
//
|
||||
// // Add event listener for when the app comes back online
|
||||
// const unsubscribe = NetInfo.addEventListener(state => {
|
||||
// if (state.isConnected) {
|
||||
// retryOfflineRequests(mutation);
|
||||
// }
|
||||
// });
|
||||
//
|
||||
// return () => {
|
||||
// unsubscribe();
|
||||
// };
|
||||
// }, [mutation]);
|
||||
|
||||
const handleSubmit = (data) => {
|
||||
mutation.mutate(data);
|
||||
@ -38,8 +38,6 @@ const MyComponent = () => {
|
||||
return (
|
||||
<View>
|
||||
<Button onPress={() => handleSubmit({ title: 'New Todo' })} title="Add Todo" />
|
||||
{mutation.isLoading && <Text>Loading...</Text>}
|
||||
{mutation.isError && <Text>Error: {mutation.error.message}</Text>}
|
||||
</View>
|
||||
);
|
||||
};
|
||||
|
@ -6,7 +6,7 @@ import { sendRequest } from './api';
|
||||
const useOfflineMutation = () => {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
const mutation = useMutation(sendRequest, {
|
||||
const mutation = queryClient.setMutationDefaults(sendRequest, {
|
||||
onMutate: async (newData) => {
|
||||
await queryClient.cancelQueries('data');
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user