nextjs getinitialprops not working 1

nextjs getinitialprops not working

//Try not use axios if you're using it.
//if not try use exactly this syntax
export async function getStaticProps() {
  const res = await fetch(`http://localhost:3000/api/blogs`)
  const Blogs = await res.json()
  return {
    props: {
      Blogs,
    },
  }
}

Here is what the above code is Doing:
1. We’re using the getStaticProps function to fetch data from our API.
2. We’re returning the data as props.
3. We’re using the data in our component.

Now, let’s see how we can use the data in our component.

Similar Posts