// CustomerPage.tsx
import { useQuery } from '@tanstack/react-query';
const CustomerPage = () => {
const { data:customer, isFetching } = useQuery({
queryKey: ['customer', '123'],
queryFn: async () => {
const response = await fetch( `/api/customer/123` );
return response.json();
// Your API call here
},
});
return (
<div>
<h1>Customer Page</h1>
{ isFetching && <p>Loading customer data...</p> }
{ customer && customer.data && (
<div>
<h2>Customer Details</h2>
<p><strong>Name:</strong> { customer.data.name1 } { customer.data.name2 }</p>
</div>
) }
</div>
);
}
export default CustomerPage;
// CustomerPage.tsx
import { useQuery } from '@tanstack/react-query';
const CustomerPage = () => {
const { data:customer, isFetching } = useQuery({
queryKey: ['customer', '123'],
queryFn: async () => {
const response = await fetch( `/api/customer/123` );
return response.json();
// Your API call here
},
});
return (
<div>
<h1>Customer Page</h1>
{ isFetching && <p>Loading customer data...</p> }
{ customer && customer.data && (
<div>
<h2>Customer Details</h2>
<p><strong>Name:</strong> { customer.data.name1 } { customer.data.name2 }</p>
</div>
) }
</div>
);
}
export default CustomerPage;