Wondering what’s next for npm?Check out our public roadmap! »

    gatsby-plugin-global-context

    1.0.0 • Public • Published

    gatsby-plugin-global-context

    Gatsby plugin to apply context to every page

    Travis npm

    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:

    module.exports = {
      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';
     
    export default () => <h1>Hi, I am a page</h1>;
     
    export 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-context
    cd gatsby-plugin-global-context
    npm install
    npm test

    License

    MIT © Geoff Kimball

    Install

    npm i gatsby-plugin-global-context

    DownloadsWeekly Downloads

    441

    Version

    1.0.0

    License

    MIT

    Unpacked Size

    5.51 kB

    Total Files

    7

    Last publish

    Collaborators

    • avatar