Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
This code snippet is an example of using getInitialProps to enable server-side rendering for a React application with Next.js. This code snippet is from the article originally published on RubyGarage’s blog:
function Page({ stars }) {
return <div>Next stars: {stars}</div>
Page.getInitialProps = async (ctx) => {
const res = await fetch('')
const json = await res.json()
return { stars: json.stargazers_count }
export default Page
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment