Skip to content

Instantly share code, notes, and snippets.

@katesroad
Last active September 30, 2021 20:20
Show Gist options
  • Save katesroad/0122fe29306a5d59087c5de014befe53 to your computer and use it in GitHub Desktop.
Save katesroad/0122fe29306a5d59087c5de014befe53 to your computer and use it in GitHub Desktop.
Pagination for react-query
import { useQuery } from "react-query";
const useGetTableData = () => {
const queryKey = ["table", "data"];
const queryFn = () =>
new Promise((resolve) =>
resolve({
data: [],
total: 100
})
);
return useQuery(queryKey, queryFn, {
keepPreviousData: true
});
};
const UserTable = () => {
const { isLoading, isPreviousData } = useGetTableData();
const showSpinner = isLoading || isPreviousData;
return <table></table>;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment