Which strategy should I use for How to Migrate Deprecated Gatsby StaticQuery Usage Before Gatsby 6?

Teams on Gatsby 5 need to decide how to migrate deprecated StaticQuery usage before Gatsby 6 turns the v5 deprecation into a breaking removal.

Replace `<StaticQuery />` with `useStaticQuery` in place if each use can be converted locally; refactor into shared hooks only when repeated queries are causing real duplication.

Blockers

Who this is for

Candidates

Replace "<StaticQuery />" with "useStaticQuery" in place

Convert each deprecated "<StaticQuery />" component directly to the documented "useStaticQuery" replacement while keeping the existing component structure mostly intact.

When to choose

Best for small-team + low-ops Gatsby 5 sites that want the shortest path to removing the Gatsby 6 blocker. Choose this when each deprecated component can be converted locally without redesigning how shared data is exposed.

Tradeoffs

Fastest migration and closest to current behavior, but repeated query snippets can remain duplicated across components.

Cautions

Do not assume the replacement is drop-in if the query file lives outside "src" or if a file already needs more than one static query. The hook also cannot take variables, so keep truly dynamic data in page queries instead.

Refactor shared StaticQuery usage into reusable custom "useStaticQuery" hooks

Move repeated shared-data queries into reusable custom "useStaticQuery" hooks so multiple components can consume the same static data through a centralized abstraction.

When to choose

Best for small-team + low-ops codebases with repeated shared-data queries across many components. Choose this when you want the Gatsby 6 cleanup to also reduce duplicated GraphQL snippets and standardize call sites.

Tradeoffs

Cleaner reuse and less repeated query text, but it touches more component imports and still follows React hook rules.

Cautions

Custom hooks inherit the same official "useStaticQuery" limitations: no variables, one instance per file, and the hook files must remain under "src". If the shared abstraction currently depends on page context or runtime values, this pattern is the wrong fit.

Facts updated: 2026-04-03
Published: 2026-04-04

Try with your AI agent

$ npm install -g pocketlantern
$ pocketlantern init
# Restart Claude Code, Cursor, or your MCP client, then ask:
# "Which strategy should I use for How to Migrate Deprecated Gatsby StaticQuery Usage Before Gatsby 6?"
Missing something? Request coverage