Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/react/use_paginated_query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,13 @@ export function usePaginatedQueryInternal<
setState(currState);
}
const convexClient = useConvex();
if (convexClient === undefined) {
throw new Error(
"Could not find Convex client! `usePaginatedQuery` must be used in the React component " +
"tree under `ConvexProvider`. Did you forget it? " +
"See https://docs.convex.dev/quick-start#set-up-convex-in-your-react-app",
);
}
const logger = convexClient.logger;

const resultsObject = useQueries(currState.queries);
Expand Down
7 changes: 7 additions & 0 deletions src/react/use_paginated_query2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,13 @@ export function usePaginatedQuery_experimental<
const argsObject = skip ? {} : queryArgs;

const convexClient = useConvex();
if (convexClient === undefined) {
throw new Error(
"Could not find Convex client! `usePaginatedQuery_experimental` must be used in the React component " +
"tree under `ConvexProvider`. Did you forget it? " +
"See https://docs.convex.dev/quick-start#set-up-convex-in-your-react-app",
);
}
const logger = convexClient.logger;

// The identity of createInitialState changes each time!
Expand Down
24 changes: 24 additions & 0 deletions src/react/use_paginated_query_provider.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* @vitest-environment jsdom
*/
import { renderHook } from "@testing-library/react";
import { expect, test } from "vitest";
import { makeFunctionReference } from "../server/index.js";
import { usePaginatedQuery } from "./use_paginated_query.js";
import { usePaginatedQuery_experimental } from "./use_paginated_query2.js";

const query = makeFunctionReference<"query">("messages:list") as any;

test("usePaginatedQuery names itself when there is no ConvexProvider", () => {
expect(() =>
renderHook(() => usePaginatedQuery(query, {}, { initialNumItems: 1 })),
).toThrow("Could not find Convex client! `usePaginatedQuery`");
});

test("usePaginatedQuery_experimental names itself when there is no ConvexProvider", () => {
expect(() =>
renderHook(() =>
usePaginatedQuery_experimental(query, {}, { initialNumItems: 1 }),
),
).toThrow("Could not find Convex client! `usePaginatedQuery_experimental`");
});