Skip to content

Commit

Permalink
gatsby-starter-default useStaticQuery over StaticQuery (#12004)
Browse files Browse the repository at this point in the history
* seo.js StaticQuery -> useStaticQuery

* layout.js StaticQuery -> useStaticQuery

* updated gatsby, react, & react DOM for starters

* SEO component doc link + imported to blog starter

* Revert "layout.js StaticQuery -> useStaticQuery"

This reverts commit 83e8056.

* Added comments explaining StaticQuery vs useStaticQuery examples
  • Loading branch information
DylanTackoor authored and wardpeet committed Feb 27, 2019
1 parent 89b69be commit d7228a6
Show file tree
Hide file tree
Showing 7 changed files with 712 additions and 772 deletions.
538 changes: 243 additions & 295 deletions starters/blog/package-lock.json

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions starters/blog/src/components/bio.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/**
* Bio component that queries for data
* with Gatsby's StaticQuery component
*
* See: https://www.gatsbyjs.org/docs/static-query/
*/

import React from "react"
import { StaticQuery, graphql } from "gatsby"
import Image from "gatsby-image"
Expand Down
142 changes: 72 additions & 70 deletions starters/blog/src/components/seo.js
Original file line number Diff line number Diff line change
@@ -1,68 +1,82 @@
/**
* SEO component that queries for data with
* Gatsby's useStaticQuery React hook
*
* See: https://www.gatsbyjs.org/docs/use-static-query/
*/

import React from "react"
import PropTypes from "prop-types"
import Helmet from "react-helmet"
import { StaticQuery, graphql } from "gatsby"
import { useStaticQuery, graphql } from "gatsby"

function SEO({ description, lang, meta, keywords, title }) {
const { site } = useStaticQuery(
graphql`
query {
site {
siteMetadata {
title
description
author
}
}
}
`
)

const metaDescription = description || site.siteMetadata.description

return (
<StaticQuery
query={detailsQuery}
render={data => {
const metaDescription =
description || data.site.siteMetadata.description
return (
<Helmet
htmlAttributes={{
lang,
}}
title={title}
titleTemplate={`%s | ${data.site.siteMetadata.title}`}
meta={[
{
name: `description`,
content: metaDescription,
},
{
property: `og:title`,
content: title,
},
{
property: `og:description`,
content: metaDescription,
},
{
property: `og:type`,
content: `website`,
},
{
name: `twitter:card`,
content: `summary`,
},
{
name: `twitter:creator`,
content: data.site.siteMetadata.author,
},
{
name: `twitter:title`,
content: title,
},
{
name: `twitter:description`,
content: metaDescription,
},
]
.concat(
keywords.length > 0
? {
name: `keywords`,
content: keywords.join(`, `),
}
: []
)
.concat(meta)}
/>
)
<Helmet
htmlAttributes={{
lang,
}}
title={title}
titleTemplate={`%s | ${site.siteMetadata.title}`}
meta={[
{
name: `description`,
content: metaDescription,
},
{
property: `og:title`,
content: title,
},
{
property: `og:description`,
content: metaDescription,
},
{
property: `og:type`,
content: `website`,
},
{
name: `twitter:card`,
content: `summary`,
},
{
name: `twitter:creator`,
content: site.siteMetadata.author,
},
{
name: `twitter:title`,
content: title,
},
{
name: `twitter:description`,
content: metaDescription,
},
]
.concat(
keywords.length > 0
? {
name: `keywords`,
content: keywords.join(`, `),
}
: []
)
.concat(meta)}
/>
)
}
Expand All @@ -82,15 +96,3 @@ SEO.propTypes = {
}

export default SEO

const detailsQuery = graphql`
query DefaultSEOQuery {
site {
siteMetadata {
title
description
author
}
}
}
`
Loading

0 comments on commit d7228a6

Please sign in to comment.