From 5a61a1a84684fbaa000dfa2cdc8ff9d41a1ac2a8 Mon Sep 17 00:00:00 2001 From: Allie Stehney <30774372+alliestehney@users.noreply.github.com> Date: Sat, 26 Oct 2019 11:19:48 -0400 Subject: [PATCH] Mention useStaticQuery hook in documentation (#18920) Adds a mention of the new `useStaticQuery` hook in the Static Query vs. Normal Query documentation. Points users to helpful Gatsby documentation on how to use `useStaticQuery` to query data at build time. --- docs/docs/static-vs-normal-queries.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/docs/docs/static-vs-normal-queries.md b/docs/docs/static-vs-normal-queries.md index 7d8c77b1b1c05..f85fe309465e2 100644 --- a/docs/docs/static-vs-normal-queries.md +++ b/docs/docs/static-vs-normal-queries.md @@ -6,7 +6,6 @@ title: Static vs Normal Queries > > Outdated areas are: > -> - mention the useStaticQuery hook > - describe how queries are stripped and JSON imports are rewritten > > You can help by making a PR to [update this documentation](https://github.com/gatsbyjs/gatsby/issues/14228). @@ -18,8 +17,15 @@ StaticQuery can do most of the things that page query can, including fragments. - page queries can accept variables (via `pageContext`) but can only be added to _page_ components - StaticQuery does not accept variables (hence the name "static"), but can be used in _any_ component, including pages - StaticQuery does not work with raw React.createElement calls; please use JSX, e.g. `` + - _NOTE: you can also use the new `useStaticQuery` hook; more information below_ - Static Queries don't need to get run for each page.(ie:Just once) +## useStaticQuery hook + +- Gatsby v2.1.0 introduces `useStaticQuery`, a Gatsby feature that allows you to use a React hook to query GraphQL +- `useStaticQuery` is a hook, contrary to `` which is a component +- Check out [how to query data at build time using `useStaticQuery`](https://www.gatsbyjs.org/docs/use-static-query/) + ### staticQueryComponents Started here because they're referenced in page-query-runner:findIdsWithDataDependencies.