Get next post in Next/React

I'm trying to link to the next post (if there is one) when on a single post page in my Next.js project. My code below is based on the solution here but I'm not able to get it working.

I query the next news post:
const nextpost = await client.query(Prismic.Predicates.at('document.type', 'news'), { pageSize : 1 , after : ${doc.id}, orderings: '[my.post.date]'})

Then use that query for the link:

<Link as={linkResolver(nextpost)} href={hrefResolver(nextpost)}>
  Next post
</Link>

Any ideas?

Hey Mike,

Thanks for posting this question. I think it's a great implementation.

What's the repo you're working with? To get started, I'll see if I can get things working on my side.

Sam

Mike and I discussed this a bit by DM and found a resolution.

Here is the GitHub repo for the solution, with some instructions for implementation:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.