Using Next.js and Clerk, how can I set up Next.js prefetching to be able to prefetch this query? I have a next/link in a server component pointing to this route but it doesn't seem to be prefetching.
// convex/customers.ts
export const listByUser = query({
args: {},
handler: async (ctx) => {
const identity = await requireAuth(ctx);
const customers = await ctx.db
.query("customers")
.withIndex("userId", (q) => q.eq("userId", identity.userId as string))
.order("desc")
.collect();
return customers;
},
});
// app/customers/page.tsx
import Link from "next/link";
import { PlusCircle } from "lucide-react";
import { preloadQuery } from "convex/nextjs";
import { api } from "@/convex/_generated/api";
import { Button } from "@/components/ui/button";
import { CustomersTable } from "@/components/customers/customers-table";
import { TableSkeleton } from "@/components/skeletons/table-skeleton";
import { getAuthToken } from "@/lib/auth";
export default async function Page() {
const token = await getAuthToken();
const preloadedCustomers = await preloadQuery(
api.customers.listByUser,
{},
{ token },
);
return (
<div className="p-5">
<div className="mb-6 flex items-center justify-between">
<h1 className="text-3xl font-bold tracking-tight">Customers</h1>
<Button asChild>
<Link href="/customers/new">
<PlusCircle className="mr-2 h-4 w-4" />
Add Customer
</Link>
</Button>
</div>
{preloadedCustomers === undefined ? (
<TableSkeleton />
) : (
<CustomersTable preloadedCustomers={preloadedCustomers} />
)}
</div>
);
}