changes
This commit is contained in:
parent
a2ec812ba7
commit
e8e3cc70ab
0
android/gradlew
vendored
Normal file → Executable file
0
android/gradlew
vendored
Normal file → Executable file
@ -1,51 +1,26 @@
|
|||||||
import React, { useState } from 'react'
|
import React, {useState} from 'react';
|
||||||
import { usePlaceOrder } from './usePlaceOrder'
|
import {ToastAndroid, Text, View, Button} from 'react-native';
|
||||||
import {ToastAndroid} from 'react-native';
|
import {useMutation} from '@tanstack/react-query';
|
||||||
|
|
||||||
function OrderComponent() {
|
function OrderComponent() {
|
||||||
const { mutate, isLoading, isError, error, data } = usePlaceOrder()
|
const mutation = useMutation(['placeOrder']);
|
||||||
const [orderData, setOrderData] = useState({ title: '', body: '', userId: 1 })
|
const [orderData, setOrderData] = useState({title: '', body: '', userId: 1});
|
||||||
|
|
||||||
const handlePlaceOrder = () => {
|
const handlePlaceOrder = id => {
|
||||||
mutate(orderData)
|
mutation.mutate({title: '', body: '', userId: id});
|
||||||
}
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<View>
|
||||||
<h1>Place Order</h1>
|
<Text>Place Order</Text>
|
||||||
<form
|
<Button
|
||||||
onSubmit={(e) => {
|
title="Make order"
|
||||||
e.preventDefault()
|
onPress={handlePlaceOrder(Math.floor(Math.random() * 100))}
|
||||||
handlePlaceOrder()
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div>
|
|
||||||
<label>
|
|
||||||
Title:
|
|
||||||
<input
|
|
||||||
type="text"
|
|
||||||
value={orderData.title}
|
|
||||||
onChange={(e) => setOrderData({ ...orderData, title: e.target.value })}
|
|
||||||
/>
|
/>
|
||||||
</label>
|
{mutation.isError && <Text>Error: {mutation.error.message}</Text>}
|
||||||
</div>
|
{mutation.data && <Text>Order ID: {mutation.data.id}</Text>}
|
||||||
<div>
|
</View>
|
||||||
<label>
|
);
|
||||||
Body:
|
|
||||||
<textarea
|
|
||||||
value={orderData.body}
|
|
||||||
onChange={(e) => setOrderData({ ...orderData, body: e.target.value })}
|
|
||||||
/>
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
<button type="submit" disabled={isLoading}>
|
|
||||||
{isLoading ? 'Placing Order...' : 'Place Order'}
|
|
||||||
</button>
|
|
||||||
</form>
|
|
||||||
{isError && <p>Error: {error.message}</p>}
|
|
||||||
{data && <p>Order ID: {data.id}</p>}
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default OrderComponent
|
export default OrderComponent;
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
import { QueryClient, MutationCache } from '@tanstack/react-query'
|
import { QueryClient, MutationCache } from '@tanstack/react-query';
|
||||||
import { createSyncStoragePersister } from '@tanstack/query-sync-storage-persister'
|
import { createAsyncStoragePersister } from '@tanstack/query-async-storage-persister';
|
||||||
|
import AsyncStorage from '@react-native-async-storage/async-storage';
|
||||||
import {ToastAndroid} from 'react-native';
|
import {ToastAndroid} from 'react-native';
|
||||||
|
|
||||||
// Create a persister using localStorrage
|
// Create a persister using localStorrage
|
||||||
const persister = createSyncStoragePersister({
|
const persister = createAsyncStoragePersister({
|
||||||
storage: window.localStorage,
|
storage: AsyncStorage,
|
||||||
})
|
})
|
||||||
|
|
||||||
// Create a QueryClient instance
|
// Create a QueryClient instance
|
||||||
@ -13,6 +14,9 @@ const queryClient = new QueryClient({
|
|||||||
mutations: {
|
mutations: {
|
||||||
retry: true, // Retry indefinitely
|
retry: true, // Retry indefinitely
|
||||||
},
|
},
|
||||||
|
queries: {
|
||||||
|
gcTime: 1000 * 60 * 60 * 24, // 24 hours
|
||||||
|
},
|
||||||
},
|
},
|
||||||
mutationCache: new MutationCache({
|
mutationCache: new MutationCache({
|
||||||
onSuccess: (data) => {
|
onSuccess: (data) => {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { useMutation } from '@tanstack/react-query'
|
import { useMutation } from '@tanstack/react-query'
|
||||||
|
|
||||||
export function usePlaceOrder() {
|
export function usePlaceOrder() {
|
||||||
return useMutation(['placeOrder'])
|
return useMutation(['placeOrder']);
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
{
|
{
|
||||||
"extends": "@react-native/typescript-config/tsconfig.json"
|
"extends": "@react-native/typescript-config/tsconfig.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"allowJs": true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user