简体   繁体   中英

Gatsby.js (React) - graphql query in gatsby-browser.js

I have a plugin TypeWriting in Gatsby.js (React). It looks like this:

/* file: gatsby-browser.js */
const typeWriting = () => {
  new Typewriter('#intro-typing', {
    strings: ['Drupal', 'WordPress', 'OpenCart'],
  });
}
export const onInitialClientRender = () => {
  typeWriting();
}

I want to set for "string" - own array from graphql query

How I can work with graphql query in gatsby-browser.js ?

gatsby-browser.js is a file that lets you respond to actions within the browser, and wrap your site in additional components. The Gatsby Browser API gives you many options for interacting with the client-side of Gatsby . So I don't think that you can trigger, outside any API or method, any kind of GraphQL query.

If you want that strings array to be "automated" you can use environment variables and get place it as values of the array.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM