I tried the second example of fetching, and I get this error (nextjs version: 2.1.1):
const Page = ({ stars }) => <div>Next stars: {stars}</div>
Page.getInitialProps = async ({ req }) => {
const res = await fetch('https://api.github.com/repos/zeit/next.js')
const json = await res.json()
return { stars: json.stargazers_count }
}
export default Page
You may need to import a package like this: https://www.npmjs.com/package/isomorphic-unfetch which works both on the server and client.
Follow this tutorial: https://learnnextjs.com/basics/fetching-data-for-pages
Most helpful comment
You may need to import a package like this: https://www.npmjs.com/package/isomorphic-unfetch which works both on the server and client.
Follow this tutorial: https://learnnextjs.com/basics/fetching-data-for-pages