Real-time updates with Sanity watch mode
Watch mode allows you to see realtime updates without having to manually restart the build process.
Set watchMode: true
in your gatsby-sanity-source
plugin options, to set up a listener which watches your project for changes.
Take it further by setting overlayDrafts: true
to immediately apply any changes you make to draft content.
You will then need to generate a token from the Sanity manage console.
Navigate to manage.sanity.io
> settings > API > Add New Token.
Create a Read token called Gatsby and add to your gatsby-config.js.
{
resolve: "gatsby-source-sanity",
options: {
projectId: "your_project_id",
dataset: "your_dataset_name",
overlayDrafts: true,
watchMode: true,
token: 'your_token_id'
}
}
Restart gatsby develop
.
Now when you edit content in the Studio CMS you will see changes occur in Gatsby in realtime.