Created
October 10, 2018 00:42
-
-
Save cwlsn/aee06c58dc45955cf4d494c4e335cf58 to your computer and use it in GitHub Desktop.
Rendering Content with Gatsby StaticQuery
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react"; | |
import { StaticQuery, graphql } from "gatsby"; | |
const HomePage = () => ( | |
<StaticQuery | |
query={graphql` | |
query HomePage { | |
contentfulHomePage { | |
title | |
date | |
content { | |
content | |
} | |
image { | |
file { | |
url | |
} | |
} | |
} | |
} | |
`} | |
render={({ | |
contentfulHomePage: { | |
title, | |
date, | |
content: { content }, | |
image: { | |
file: { url } | |
} | |
} | |
}) => ( | |
<> | |
<h1>{title}</h1> | |
<small>Created on {date}</small> | |
<img src={url} /> | |
<p>{content}</p> | |
</> | |
)} | |
/> | |
); | |
export default HomePage; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment