Gatsby: How to use context without graphQL query?

Created on 7 Dec 2018  路  2Comments  路  Source: gatsbyjs/gatsby

Hi,

I created pages using an array. And I would like to path letters in context but I doesn't work because it seems I have to use it in GraphQL queries.

What is the solution to use context outside of GraphQL queries, such as props maybe?

Thanks


  'abcdefghijklmnopqrstuvwxyz'.split('').map(letter => {
    createPage({
      path: `definitions/${letter}`,
      component: path.resolve('src/templates/definitions.js'),
      context: {
        letter,
      },
    });
  });

question or discussion

Most helpful comment

hi the context is being passed as prop automatically. you can use it in your page template like this if you are working with the v2 of gatsby:
const { pathContext } = this.props;
cost { letter } = pathContext;

All 2 comments

hi the context is being passed as prop automatically. you can use it in your page template like this if you are working with the v2 of gatsby:
const { pathContext } = this.props;
cost { letter } = pathContext;

hi the context is being passed as prop automatically. you can use it in your page template like this if you are working with the v2 of gatsby:
const { pathContext } = this.props;

Perfect, so simple! Thanks @arturhenryy!!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dustinhorton picture dustinhorton  路  3Comments

signalwerk picture signalwerk  路  3Comments

KyleAMathews picture KyleAMathews  路  3Comments

ghost picture ghost  路  3Comments

dustinhorton picture dustinhorton  路  3Comments