This is a guide to explain how to set-up on-demand revalidation in a Sanity Nextjs project. Read the article. Visit the live demo to see the project live.
This template uses the following versions:
- Nextjs:
v14.0.4
- next-sanity:
v7.0.4
- sanity:
3.21.3
- React:
v18
File(s) | Description |
---|---|
sanity.config.ts |
Config file for Sanity Studio |
sanity.client.ts |
Config file for Sanity CLI |
studio |
Where Sanity Studio is mounted |
schemas |
Where Sanity Studio gets its content types from |
sanity.query.ts |
Where Sanity data is described and retrieved |
route.ts |
Route handler for triggering on-demand revalidation |
- clone repository
git clone https://github.com/Evavic44/sanity-nextjs-revalidation.git
cd sanity-nextjs-revalidation
npm install
- Rename
.env.example
to.env
-
NEXT_PUBLIC_SANITY_PROJECT_ID
Set to your project ID -
NEXT_PUBLIC_SANITY_DATASET
Set to "server" or a new project dataset. -
NEXT_PUBLIC_SANITY_API_VERSION
: Set to your current date in YYYY-MM-DD format or leave as is -
NEXT_PUBLIC_SANITY_ACCESS_TOKEN
Visit Sanity Manage to create an access token. -
NEXT_PUBLIC_SANITY_HOOK_SECRET
Visit Sanity Manage > API to create hook secret. -
Now run
npm run dev
Visit http://localhost:3000 to see your site
Visit http://localhost:3000/studio to edit content