Tutorial Part 6 - Blog page prop returns undefined from allMdx after moving index.js into blog folder #38917
Unanswered
nickburczyk
asked this question in
Help
Replies: 2 comments 1 reply
-
Only thing I have done that works (but it is a suboptimal workaround) is to use const BlogPage = () => {
const data = useStaticQuery(graphql`
query {
allMdx {
nodes {
frontmatter {
title
date(fromNow: true)
}
id
excerpt
}
}
}
`)
const posts = data?.allMdx?.nodes
console.log('posts', posts);
return (
<Layout pageTitle="My Blog Posts">
// ... more jsx return
</Layout>
)
} |
Beta Was this translation helpful? Give feedback.
0 replies
-
Hi Nick, How do you create/register your blog index page ? With File System route API or with Node API / And then, why do you want to move your file outside the
Arthur. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I am following the tutorial for my first Gatsby site and have run into a problem. I had no problem creating the dynamic blog post page. But as soon as I moved
blog.js
into theblog
folder and renamed toindex.js
, the page renders fine, but thedata
prop in the newsrc/blog/index.js
file returnsundefined
. Running the query in the GraphiQL browser does return the correct data.Attempted solutions
gatsby clean && gatsby develop
in the terminal. Interestingly, there are no terminal errors in the running development serverconst posts = data?.allMdx?.nodes
- This works to render the page but there are no postsconst BlogPage = ({ data = query }) => {
File Structure
src/blog/index.js
codeScreenshot of browser error
Screenshot of perfectly happy terminal
Beta Was this translation helpful? Give feedback.
All reactions