CashedC
Convex Community6mo ago
2 replies
Cashed

Preloading Next.js thread messages and then reading them with useThreadMessages

Hey there, I am trying to preload useThreadMessages using preloadQuery but running into some issues.

Preloading in my Next.js page component like:


const preloadedMessages = await preloadQuery(api.chat.listMessages, {
threadId,
paginationOpts: {
numItems: 10,
cursor: null,
},
});


And then trying to figure out the syntax to pass this to useThreadMessages. Right now my error is


const messages = useThreadMessages(
preloadedMessages,
{ threadId },
{ initialNumItems: 10, stream: true },
);


Anyone have experience preloading thread messages in Next.js then passing them to useThreadMessages so they are reactive? Using the agent component and Nextjs package.
Was this page helpful?