I know that querying is supposed to work in the layouts folder of a GatsbyJS project:
However, my code for the one layout component I am using GraphQL on, is not working, and my this.props.data console logs as 'undefined'. Why is this happening!? I'm so sure that my code is correct, what am I missing??
here is my code:
import React, { Component } from 'react'
export default class Header extends Component {
render() {
// const latestPost = this.props.data.allContentfulBlogPost.edges[1]
// const secondLatestPost = this.props.data.allContentfulBlogPost.edges[2]
console.log(this.props.data)
return (
<div className='container-fluid bottom-margin-large'>
<div className='row'>
<div className='hidden-lg-up header-solink-bar'>0 0 0 0 0</div>
</div>
<div className='row'>
<div className='header-middle'>Blog Title</div>
</div>
<div className='row header-bottom'>
<div className='col-md-6 col-lg-4 header-bottom-input'>
<div><p><span>for recipe updates</span><br />Subscribe to newsletter</p></div>
<form>
<input className='search-input' type='text' name='search' placeholder='search' />
</form>
</div>
<div className='hidden-sm-down col-md-6 col-lg-4 header-bottom-button header-bottom-middle'>
<p><span>date</span><br />name of dessert</p>
</div>
<div className='hidden-md-down col-lg-4 header-bottom-button'>
<p><span>date</span><br />name of dessert</p>
</div>
</div>
</div>
);
}
}
export const headerQuery = graphql`
query headerQuery {
allContentfulBlogPost {
edges {
node {
postTitle
postDate
}
}
totalCount
}
}
`
console.log(this.props)
but in your example you only haveconsole.log(this.props)
. this leads me to think its a Query issue with Graphql. If you could please give more information that would be great. - William