gatsby-plugin-global-context
Gatsby plugin to apply context to every page
This plugin adds context values to every page in your Gatsby project. Use this if you want to add a "global variable" that any page can use in its GraphQL query.
Installation
npm install gatsby-plugin-global-context
Usage
Add the plugin to gatsby-config.js
:
moduleexports = plugins: resolve: 'gatsby-plugin-global-context' options: context: kittens: true ;
Now, any page will have access to the values defined in context
above. This includes pages in your pages/
folder, and pages created with Gatsby's createPage()
.
import React from 'react';import graphql from 'gatsby'; <h1>Hi I am a page</h1>; const query = graphql` query PageQuery($kittens: Boolean!) { # ... }`;
Options
The only option is context
, which should be an object of context values to add to every page.
Local Development
git clone https://github.com/gakimball/gatsby-plugin-global-contextcd gatsby-plugin-global-contextnpm installnpm test
License
MIT © Geoff Kimball