Go Pro Sign Up Login

Buy Now and unlock this series

$

44

.99

$

34

.99

yours forever

Become a Pro and unlock everything

$

24

.99

per month

Context In Page Queries

Now, we are going to use context within our postLayout and gatsby-node files. Context allows us to define parameters within our post query and access our ‘slug’. This will make the heading in our postLayout file change when we click our different archived posts.

Downloads

Become a pro to download code and videos

Comments

User avatar

Raul

almost 2 years ago

@silvio If that way suits your end goal and it works you could do that too. However, this is the recommended way (see docs) for pages in Gatsby

silvio

over 2 years ago

Hey Scott, thanks for this lesson! One question:

I could just pass the title and html in gatsby-node.js via context, then it would be available as a prop in the component. I think that's much cleaner (abstracting away the graphql part). The page query seems like an unnecessary logical detour. What's the benefit of page queries?

Cheers -Silvio

Want to join the conversation?

Become a Pro member today!