cdcasey.dev

gatsbyhireactsite info

Adding Posts

So it's finally time to have posts show up on my blog's home page. Still following this tutorial, I add the graphql query. When it comes to create a type for my home page props, I create this:

1type HomeProps = {
2 data: {
3 allMdx: {
4 nodes: [
5 {
6 excerpt: string;
7 frontmatter: {
8 title: string;
9 date: string;
10 };
11 },
12 ];
13 };
14 };
15};

It seems unweildy, and I strongly suspect that there's a more sensible way to do this. But it works for now so I decide to keep it. I also notice that as I'm developing it, my code keeps compiling and running even when there's a type mismatch. It's then that I remeber that the gatsby plugin doesn't do type checking. Relying on VS Code's errors, I push on. It's time to get into the node file.

My big takeaway from working on the gatsby-node.js file is that the context part of the createPage API call not only goes into the page template's graphql query, but it also goes into the component's pageContext prop.

next: Adding Prism

prev: Adding TypeScript