TRPC Problem
i have this tweetRouter with a timeline query, which returns tweets and a NextCursor, but when i try to access useInfiniteQuery in my components a error show up.
** Property 'useInfiniteQuery' does not exist on type '{ useQuery: **
Translation: You're trying to access useInfiniteQuery
on an object that doesn't contain it.
my component:
export function Timeline() {
const data = trpc.tweet.timeline.useInfiniteQuery(
{
limit: 10,
},
{
getNextPageParam: (lastPage) => lastPage.nextCursor,
}
);
return (
<Container maxW="xl">
<CreateTweet />
<Box
borderX="1px"
borderTop="1px"
borderColor={useColorModeValue("gray.200", "gray.700")}
>
{data?.tweets.map((tweet) => {
return <Tweet key={tweet.id} tweet={tweet} />;
})}
</Box>
</Container>
);
}
my tweet.ts router:
import { z } from "zod";
import { tweetSchema } from "../../../components/CreateTweet";
import { protectedProcedure, publicProcedure, router } from "../trpc";
export const tweetRouter = router({
create: protectedProcedure.input(tweetSchema).mutation(({ ctx, input }) => {
const { prisma, session } = ctx
const { text } = input
const userId = session.user.id
return prisma.tweet.create({
data: {
text,
author: {
connect: {
id: userId,
}
}
}
})
}),
timeline: publicProcedure.input(
z.object({
cursor: z.string().nullish(),
limit: z.number().min(1).max(100).default(10)
})
).query(async ({ ctx, input }) => {
const { prisma } = ctx
const { cursor, limit } = input
const tweets = await prisma.tweet.findMany({
take: limit + 1,
orderBy: [
{
createdAt: "desc"
}
],
cursor: cursor ? { id: cursor } : undefined,
include: {
author: {
select: {
name: true,
image: true,
id: true
}
}
}
})
let nextCursor: typeof cursor | undefined = undefined;
if (tweets.length > limit) {
const nextItem = tweets.pop() as typeof tweets[number];
nextCursor = nextItem!.id;
}
return {
tweets,
nextCursor,
};
})
})
my prisma model:
model Tweet {
id String @id @default(cuid())
text String
author User @relation(fields: [authorId], references: [id])
authorId String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
and my autocompletion only shows up useQuery and useSuspenseQuery
i'm expecting to do a infinite scroll using useInfiniteQuery