adrianhajdin / project_graphql_blog

With featured and recent posts, categories. full markdown articles, author information, comments, and much more, this fully responsive CMS Blog App is the best Blog Application that you can currently find on YouTube. And what's best of all is that you and your clients can manage the blog from a dedicated Content Management System.
https://jsmastery.pro
1.47k stars 348 forks source link

Posts fail when change to getPosts #55

Open vitormarquesds opened 1 year ago

vitormarquesds commented 1 year ago

I'm having an error in the post. I do not know if this is the version, but I didn't find a solution

blog1 vlog2

error1 error2

olamission commented 1 year ago

Hi I found a solution instead of this :

export default function Home({ posts }) {

do this

export default function Home({ posts } : any ) {

its to do with typescript. it always needs a definition type for every parameter

hellotaoworld commented 1 year ago

I think the issue is in getStaticProps() function. It should be setting "posts" as a const and then point props to posts. Please see below.

export async function getStaticProps() {
  const posts = (await getPosts()) || [];
  return {
    props: { posts }
  }
}