showing results for - "passing variable in usestaticquery"
Carl
30 Apr 2020
1// Using StaticQuery instead of useStaticQuery
2
3import React from "react"
4import Img from "gatsby-image"
5import { StaticQuery } from "gatsby"
6
7export default ({ src }) => {
8  <StaticQuery
9    query={graphql`
10      query HeadingQuery($src: String!) {
11         File(relativePath: { eq: $src }) {
12           childImageSharp { ...etc }
13         }
14    `}
15    render={data => (
16       <Img fixed={data.path.to.query} />
17    )}
18  />
19}
queries leading to this page
since the ability to pass variables to staticquery is not possible in gatsby in this approach we can query all images in advance and use the find 28 29 method to determine which image we want to use by its nameadd ability to pass variables to usestaticquery gatsby static query variablesusing variables in a usestaticquerypass variables to usestaticquery 22usestaticquery 22 with variable maxwidth as variable in gatsby guery pass variables to static query graphql 22gatsby 22 insert a variable in a querygatsby pass a variable in querypass variables to staticquerygatsby usestaticquery pass parametergatsby graphql default varablepass max width as variable in gatsbygatsby graphql staticguery variableshow to pass param to gatsby in querygatsby static query variables alldatajsonadd variables attr into staticquery pass maxwidth as variable in gatsbygatsby graphql staticquery variablesusestaticquery with variable 22const match 3d usememo 28 28 29 3d 3e data allfile edges find 28 28node 3a node 29 3d 3e src 3d 3d 3d node relativepath 29 2c 5b data 2c src 2c 5d 29 22static query pass variablepass variable in staticquerygatsby static query variablegatsby usestaticquery variablegatsby use static query variablespassing props to staticquery graphqlpass props to graphql query gatsbyusestaticquery gatsby passing variablesgatsby pass variable to static query 22pass variables to usestaticquery 22staticquery variables gatsby passing variable in usestaticquerystaticquery variablepassing variable in usestaticquery