diff --git a/android/gradlew b/android/gradlew
old mode 100644
new mode 100755
diff --git a/src/OrderComponent.js b/src/OrderComponent.js
index eda654b..a78457b 100644
--- a/src/OrderComponent.js
+++ b/src/OrderComponent.js
@@ -1,51 +1,26 @@
-import React, { useState } from 'react'
-import { usePlaceOrder } from './usePlaceOrder'
-import {ToastAndroid} from 'react-native';
+import React, {useState} from 'react';
+import {ToastAndroid, Text, View, Button} from 'react-native';
+import {useMutation} from '@tanstack/react-query';
function OrderComponent() {
- const { mutate, isLoading, isError, error, data } = usePlaceOrder()
- const [orderData, setOrderData] = useState({ title: '', body: '', userId: 1 })
+ const mutation = useMutation(['placeOrder']);
+ const [orderData, setOrderData] = useState({title: '', body: '', userId: 1});
- const handlePlaceOrder = () => {
- mutate(orderData)
- }
+ const handlePlaceOrder = id => {
+ mutation.mutate({title: '', body: '', userId: id});
+ };
return (
-
-
Place Order
-
- {isError &&
Error: {error.message}
}
- {data &&
Order ID: {data.id}
}
-
- )
+
+ Place Order
+
+ {mutation.isError && Error: {mutation.error.message}}
+ {mutation.data && Order ID: {mutation.data.id}}
+
+ );
}
-export default OrderComponent
+export default OrderComponent;
diff --git a/src/queryClient.js b/src/queryClient.js
index f47e2c9..f9e6f21 100644
--- a/src/queryClient.js
+++ b/src/queryClient.js
@@ -1,10 +1,11 @@
-import { QueryClient, MutationCache } from '@tanstack/react-query'
-import { createSyncStoragePersister } from '@tanstack/query-sync-storage-persister'
+import { QueryClient, MutationCache } from '@tanstack/react-query';
+import { createAsyncStoragePersister } from '@tanstack/query-async-storage-persister';
+import AsyncStorage from '@react-native-async-storage/async-storage';
import {ToastAndroid} from 'react-native';
// Create a persister using localStorrage
-const persister = createSyncStoragePersister({
- storage: window.localStorage,
+const persister = createAsyncStoragePersister({
+ storage: AsyncStorage,
})
// Create a QueryClient instance
@@ -13,6 +14,9 @@ const queryClient = new QueryClient({
mutations: {
retry: true, // Retry indefinitely
},
+ queries: {
+ gcTime: 1000 * 60 * 60 * 24, // 24 hours
+ },
},
mutationCache: new MutationCache({
onSuccess: (data) => {
diff --git a/src/usePlaceOrder.js b/src/usePlaceOrder.js
index dcae604..4992c55 100644
--- a/src/usePlaceOrder.js
+++ b/src/usePlaceOrder.js
@@ -1,5 +1,5 @@
import { useMutation } from '@tanstack/react-query'
export function usePlaceOrder() {
- return useMutation(['placeOrder'])
+ return useMutation(['placeOrder']);
}
diff --git a/tsconfig.json b/tsconfig.json
index 304ab4e..d40f072 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -1,3 +1,6 @@
{
- "extends": "@react-native/typescript-config/tsconfig.json"
+ "extends": "@react-native/typescript-config/tsconfig.json",
+ "compilerOptions": {
+ "allowJs": true
+ }
}