Skip to content

Instantly share code, notes, and snippets.

@PavlikPolivka
Created November 11, 2021 20:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PavlikPolivka/f6025705492c96396c3d94c8fc23cc8f to your computer and use it in GitHub Desktop.
Save PavlikPolivka/f6025705492c96396c3d94c8fc23cc8f to your computer and use it in GitHub Desktop.
Blog.getInitialProps = async ({ query }) => {
const page = query.page || 1; //if page empty we request the first page
const response = await fetch(`${server}/api/posts/${page}`)
const posts = await response.json()
return {
totalCount: posts.totalCount,
pageCount: posts.pageCount,
currentPage: posts.currentPage,
perPage: posts.perPage,
posts: posts.posts,
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment