Learn about React Query
I learned more basic ways to use React Query, but I still don't know how to pass prams to fetch function
The first is the simplest method, which can easily manage the status.
const { isLoading, error, data, isFetching } = useQuery("repoData", () =>
fetch(
"https://api.github.com/repos/tannerlinsley/react-query"
).then((res) => res.json())
);
if (isLoading) return "Loading...";
if (error) return "An error has occurred: " + error.message;
return(<p>{data}<p/>)
The second way is useInfiniteQuery()
const {
data,
error,
fetchNextPage,
hasNextPage,
isFetchingNextPage,
status,
} = useInfiniteQuery('projects', getPopularMovies, {
getNextPageParam: (lastPage) =>
lastPage.page < lastPage.total_pages ? lastPage.page + 1 : undefined,
});
Also, React Query has the debug tool
import { ReactQueryDevtools } from 'react-query/devtools';
<ReactQueryDevtools initialIsOpen />