How to make a basic external data fetch using Next.js and import component into another

I have the code below in pages/github and when I go to localhost:3000/github the code executes as expected. I get JSON data.

function GithubAPI(props) {
  // Render posts...
  return (<div>{}</div>)

// This function gets called at build time
export async function getStaticProps() {
  // Call an external API endpoint to get posts
  const res = await fetch('')

  const data= await res.json()

  return {
    props: {

export default GithubAPI

When I import this component into another component I get problems.


import GithubAPI from './github'
function About(props) {

  return (
       <GithubAPI/>  {/* TypeError: Cannot read property 'name' of undefined */}


export default About

I do not know how the developers of Next.js expect us to structure our code so that we can make these kinds of API calls and still export our components for import into other components. How am I expected to do this?

Read more here:

Content Attribution

This content was originally published by William at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: