Skip to content

Instantly share code, notes, and snippets.

@cwlsn
Created October 10, 2018 00:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cwlsn/aee06c58dc45955cf4d494c4e335cf58 to your computer and use it in GitHub Desktop.
Save cwlsn/aee06c58dc45955cf4d494c4e335cf58 to your computer and use it in GitHub Desktop.
Rendering Content with Gatsby StaticQuery
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