add prefetch to table

This commit is contained in:
Brandon Egger 2023-03-16 19:27:19 -05:00
parent 3e9cd90f5f
commit 95756e5b37
2 changed files with 32 additions and 11 deletions

View File

@ -4,17 +4,6 @@ import { appRouter } from "~/server/api/root";
import { prisma } from "~/server/db";
import { api } from "~/utils/api";
const ResourceViewPage = (props: InferGetStaticPropsType<typeof getStaticProps>) => {
const { id } = props;
const resourceQuery = api.auditoryResource.byId.useQuery({ id });
return <>
<div>
{resourceQuery.data?.name ?? 'loading..'}
</div>
</>
};
export const getStaticPaths = async () => {
//const amountPerPage = 10;
const resources = (await prisma.auditoryResource.findMany({
@ -57,4 +46,15 @@ export async function getStaticProps(
};
}
const ResourceViewPage = (props: InferGetStaticPropsType<typeof getStaticProps>) => {
const { id } = props;
const resourceQuery = api.auditoryResource.byId.useQuery({ id });
return <>
<div>
{resourceQuery.data?.name ?? 'loading..'}
</div>
</>
};
export default ResourceViewPage

View File

@ -1,8 +1,29 @@
import { createProxySSGHelpers } from "@trpc/react-query/ssg";
import Head from "next/head";
import Link from "next/link";
import ResourceTable from "~/components/ResourceTable";
import { appRouter } from "~/server/api/root";
import { prisma } from "~/server/db";
import { api } from "~/utils/api";
export async function getStaticProps() {
const ssg = createProxySSGHelpers({
router: appRouter,
ctx: {
prisma,
session: null,
},
});
await ssg.auditoryResource.getAll.prefetch();
return {
props: {
trpcState: ssg.dehydrate(),
},
revalidate: 1,
};
}
const Resources = () => {
const query = api.auditoryResource.getAll.useQuery();