'use client';
// useQuery use client only
// Todo: server side integration.
import {
useQuery,
QueryClient,
QueryClientProvider,
} from '@tanstack/react-query';
// Create a client
const queryClient = new QueryClient();
export default function APIAllInOne() {
return (
<>
api all in one.
{/* */}
>
);
}
function Example() {
const { isPending, error, data, isFetching } = useQuery({
queryKey: ['repoData'],
queryFn: async () => {
const response = await fetch(
'https://api.github.com/repos/TanStack/query',
);
return await response.json();
},
});
if (isPending) return 'Loading...';
if (error) return 'An error has occurred: ' + error.message;
return (
{data.full_name}
{data.description}
👀 {data.subscribers_count} {' '}
✨ {data.stargazers_count} {' '}
🍴 {data.forks_count}
{isFetching ? 'Updating...' : ''}
);
}
//
// function Todos() {
// // Access the client
// const queryClient = useQueryClient()
//
// // Queries
// const query = useQuery({ queryKey: ['todos'], queryFn: getTodos })
//
// // Mutations
// const mutation = useMutation({
// mutationFn: postTodo,
// onSuccess: () => {
// // Invalidate and refetch
// queryClient.invalidateQueries({ queryKey: ['todos'] })
// },
// })
//
// return (
//
//
{query.data?.map((todo) => {todo.title} )}
//
//
{
// mutation.mutate({
// id: Date.now(),
// title: 'Do Laundry',
// })
// }}
// >
// Add Todo
//
//
// )
// }