Skip to content

Commit

Permalink
small fixes to query key, default exports
Browse files Browse the repository at this point in the history
  • Loading branch information
ejmg committed Jul 11, 2024
1 parent 81198cc commit a12286c
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 8 deletions.
5 changes: 3 additions & 2 deletions src/app/blocks/page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import BlocksTable from "@/components/BlocksTable";
import { BlocksTable } from "@/components/BlocksTable";
import getBlocks from "@/components/BlocksTable/getBlocks";
import { HydrationBoundary, QueryClient, dehydrate } from "@tanstack/react-query";

Expand All @@ -11,13 +11,14 @@ const Page = () => {
pageIndex: 0,
pageSize: 10,
};

const queryName = "BlocksTable";
const endpoint = "/api/blocks";
const errorMessage = "Failed to query data while trying to generate blocks table, please try reloading the page.";

queryClient.prefetchQuery({
queryFn: () => getBlocks({ endpoint, pageIndex: 0}),
queryKey: [queryName, defaultQueryOptions],
queryKey: [queryName, defaultQueryOptions.pageIndex],
meta: {
errorMessage,
},
Expand Down
2 changes: 1 addition & 1 deletion src/app/transactions/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const Page = () => {

queryClient.prefetchQuery({
queryFn: () => getTransactions({ endpoint, pageIndex: 0}),
queryKey: [queryName, defaultQueryOptions],
queryKey: [queryName, defaultQueryOptions.pageIndex],
meta: {
errorMessage,
},
Expand Down
4 changes: 1 addition & 3 deletions src/components/BlocksTable/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export function BlocksTable ({
const [pagination, setPagination] = useState<PaginationState>({...defaultQueryOptions});

const { data } = useSuspenseQuery({
queryKey: [queryName, pagination],
queryKey: [queryName, pagination.pageIndex],
queryFn: () => getBlocks({ endpoint, pageIndex: pagination.pageIndex }),
meta: {
errorMessage,
Expand All @@ -60,5 +60,3 @@ export function BlocksTable ({
</div>
);
};

export default BlocksTable;
1 change: 0 additions & 1 deletion src/components/Providers/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ const makeQueryClient = () => {
queries: {
// Direct suggestion by tanstack, to prevent over-eager refetching from the client.
staleTime: 60 * 1000,
refetchOnWindowFocus: false,
},
dehydrate: {
// only successful and pending Queries are included per defaults
Expand Down
2 changes: 1 addition & 1 deletion src/components/TransactionsTable/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export function TransactionsTable ({
const [pagination, setPagination] = useState<PaginationState>({...defaultQueryOptions});

const { data } = useSuspenseQuery({
queryKey: [queryName, pagination],
queryKey: [queryName, pagination.pageIndex],
queryFn: () => getTransactions({ endpoint, pageIndex: pagination.pageIndex }),
meta: {
errorMessage,
Expand Down

0 comments on commit a12286c

Please sign in to comment.