Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Cannot read property 'node' of undefined #4

Open
Qurus opened this issue Mar 7, 2021 · 1 comment
Open

TypeError: Cannot read property 'node' of undefined #4

Qurus opened this issue Mar 7, 2021 · 1 comment

Comments

@Qurus
Copy link

Qurus commented Mar 7, 2021

Featured Articles not working giving node undefined error. Any idea how can I fix that?

import React from 'react'
import { useStaticQuery, graphql } from "gatsby"
import Link from 'gatsby-link'

export default function ArticleTeaser({ blok }){
  const { articles, authors } = useStaticQuery(graphql`
  query Articles {
    articles: allStoryblokEntry(filter: {field_component: {eq: "blogpost"}}) {
      edges {
        node {
          name
          full_slug
          content
        }
      }
    }
    authors: allStoryblokEntry(filter: {field_component: {eq: "author"}}) {
      edges {
        node {
          name
          uuid
          content
        }
      }
    }
  } 
  `)
  let article = articles.edges.filter(({ node }) => node.full_slug === blok.article.cached_url)
  let content = article.length ? JSON.parse(article[0].node.content) : {};
  let  { author } = content
  let thisAuthor = authors.edges.filter(({ node }) => node.uuid === author)
  let authorContent = thisAuthor.length ? JSON.parse(thisAuthor[0].node.content) : {};

  return (
      <Link to={`/${article[0].node.full_slug}`} className="py-16 block transition hover:opacity-50">
        <img src={content.image} className="pb-10 w-full"/>
        <h2 className="pb-6 text-lg font-bold">{content.title}</h2>
        <p className="pb-6 text-gray-700 leading-loose">{content.intro}</p>
        <p className="text-gray-700">{authorContent.name}</p>
      </Link>
  )
}
@jasonTBB
Copy link

I am having the exact same issue.

Did you ever manage to figure out what the issue was?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants