{"record":{"id":"58a5146eaf2b510f","repo":"gatsbyjs/gatsby","slug":"you-re-likely-using-a-version-of-react-that-doesn","errorCode":null,"errorMessage":"You're likely using a version of React that doesn't support Hooks\nPlease update React and ReactDOM to 16.8.0 or later to use the useStaticQuery hook.","messagePattern":"You're likely using a version of React that doesn't support Hooks\nPlease update React and ReactDOM to 16\\.8\\.0 or later to use the useStaticQuery hook\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/gatsby/cache-dir/static-query.js","lineNumber":60,"sourceCode":"      )}\n    </StaticQueryContext.Consumer>\n  )\n}\n\nStaticQuery.propTypes = {\n  data: PropTypes.object,\n  query: PropTypes.string.isRequired,\n  render: PropTypes.func,\n  children: PropTypes.func,\n}\n\nconst useStaticQuery = query => {\n  if (\n    typeof React.useContext !== `function` &&\n    process.env.NODE_ENV === `development`\n  ) {\n    // TODO(v5): Remove since we require React >= 18\n    throw new Error(\n      `You're likely using a version of React that doesn't support Hooks\\n` +\n        `Please update React and ReactDOM to 16.8.0 or later to use the useStaticQuery hook.`\n    )\n  }\n\n  const context = React.useContext(StaticQueryContext)\n\n  // query is a stringified number like `3303882` when wrapped with graphql, If a user forgets\n  // to wrap the query in a grqphql, then casting it to a Number results in `NaN` allowing us to\n  // catch the misuse of the API and give proper direction\n  if (isNaN(Number(query))) {\n    throw new Error(`useStaticQuery was called with a string but expects to be called using \\`graphql\\`. Try this:\n\nimport { useStaticQuery, graphql } from 'gatsby';\n\nuseStaticQuery(graphql\\`${query}\\`);\n`)\n  }","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/gatsbyjs/gatsby/blob/8b06340921ffdf23125a365b9c9923690cb62ce6/packages/gatsby/cache-dir/static-query.js#L42-L78","documentation":"Thrown by useStaticQuery when React.useContext is not a function, checked only in development mode. Gatsby's useStaticQuery hook relies on React's useContext Hook (available since React 16.8); if the installed React version is older and lacks Hooks, the call cannot work. The check is dev-only and is a legacy guard (marked TODO for removal in v5+).","triggerScenarios":"In development (NODE_ENV !== 'production'), useStaticQuery is called with a React version below 16.8 where React.useContext is undefined. typeof React.useContext !== 'function' evaluates true, and the error fires before useContext is even called.","commonSituations":"A project has an old React/ReactDOM version in package.json (e.g. React 16.7 or earlier), a dependency or Gatsby plugin pins an old React version causing a version conflict, or the lockfile resolved to a pre-Hooks React release. Modern Gatsby requires React >= 18, so this is increasingly rare.","solutions":["Upgrade React and ReactDOM to the latest stable version: `npm install react@latest react-dom@latest`.","Ensure no dependency forces an older React version — run `npm ls react` to check for conflicts.","Delete node_modules and lockfile, then reinstall to resolve version mismatches.","Verify Gatsby version compatibility — modern Gatsby (v5+) requires React 18+."],"exampleFix":"// before — old React in package.json\n\"dependencies\": {\n  \"react\": \"^16.7.0\",\n  \"react-dom\": \"^16.7.0\"\n}\n\n// after\n\"dependencies\": {\n  \"react\": \"^18.2.0\",\n  \"react-dom\": \"^18.2.0\"\n}","handlingStrategy":"validation","validationCode":"// Verify React version supports Hooks at startup\nfunction checkReactVersion() {\n  const React = require('react')\n  if (typeof React.useContext !== 'function') {\n    throw new Error('React >= 16.8.0 required for useStaticQuery. Current: ' + React.version)\n  }\n}\ncheckReactVersion()","typeGuard":"// Type-level: declare minimum React version via package.json resolution\n// Ensure package.json specifies:\n// \"react\": \">=18.0.0\", \"react-dom\": \">=18.0.0\"\n// and run: npm ls react  to detect conflicting versions","tryCatchPattern":null,"preventionTips":["Pin React and ReactDOM to >= 18.x in package.json for modern Gatsby.","Run `npm ls react` to detect version conflicts from transitive dependencies.","Delete node_modules and lockfile if version resolution is inconsistent.","Upgrade Gatsby alongside React — version compatibility is enforced by Gatsby's peer deps."],"tags":["react","hooks","version-mismatch","use-static-query","dev-mode"],"backgroundTag":null,"analyzedSha":"8b06340921ffdf23125a365b9c9923690cb62ce6","analyzedAt":"2026-08-13T02:36:21.405Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}