justask.dev

Community powered answers to your dev questions

useSiteMetadata

posted: 2019 December 9th

category: gatsby

Edit this post on GitHub.

Back

No need to use the StaticQuery component anymore. Simplify things with this hook.

1import { useStaticQuery, graphql } from "gatsby";
2
3export const useSiteMetadata = () => {
4 const { site } = useStaticQuery(
5 graphql`
6 query SiteMetaData {
7 site {
8 siteMetadata {
9 title
10 description
11 ...allTheRest
12 }
13 }
14 }
15 `
16 );
17 return site.siteMetadata;
18};

Author: Rich Haines