Gatsby uses GraphQL to let components declare the data it needs and then gives this data to components. Suppose your DatoCMS administrative area has a single-instance model called About page (with an about_page
API identifier).
In your Gatsby project you can create an About
React component in src/pages/about.js
, and pull data from DatoCMS like this:
import React from 'react';export default const About = ({ data }) => (<article className="sheet"><h1>{data.datoCmsAboutPage.title}</h1><p>{data.datoCmsAboutPage.subtitle}</p><img src={data.datoCmsAboutPage.photo.url} /><div dangerouslySetInnerHTML={{ __html: data.datoCmsAboutPage.bio }} /></article>);export const query = graphql`query AboutQuery {datoCmsAboutPage {titlesubtitlephoto { url }bio}}`;
Obviously, that's just a simple example: you can learn all the details about how to access your records in the plugin README.
We have also prepared for you some sample projects: