gatsby-source-google-spreadsheet icon indicating copy to clipboard operation
gatsby-source-google-spreadsheet copied to clipboard

Cannot use in useStaticQuery hook

Open dspachos opened this issue 4 years ago • 1 comments

Hi,

While I can use the plugin in a page level query, I cannot use it in a component level (more specifically using the useStaticQuery method) - returns always 'undefined'.

Is there any example on how to use in a component level query?

Thanks

dspachos avatar Aug 29 '20 20:08 dspachos

Hey @dspachos i'm doing this with the following code and it works well 😄

import { useStaticQuery, graphql } from 'gatsby'

export const useZips = () => {
  const data = useStaticQuery(
    graphql`
      query ZipsQuery {
        Name1: Sheet1 {
          nodes {
            attr1
            attr2
          }
        }
        Name2: Sheet2 {
          nodes {
            attr1
            attr2
          }
        }
        Name3: Sheet3 {
          nodes {
            attr1
            attr2
          }
        }
      }
    `
  )

  return data
}

fraserisland avatar Feb 10 '21 21:02 fraserisland