DEV Community

Discussion on: Global State in Gatsby, or Having and Eating Your Cake, Too

Collapse
 
larsejaas profile image
Lars Ejaas • Edited

It's a really nice trick to have the context provider in the gatsby-browser file!
I usually just wrap the other components in the layout file, but it's better to keep the logic in a seperate file, I like that solution 😊

It's also worth noting that if you do not use class components you do not really need the consumer component at all. You simply wrap the root with the provider and then get the context values using the context hook as you have already shown. This is actually quite clever 😊