Skip to content

A simple guide to illustrate how to setup on-demand revalidation in Sanity and Nextjs app directory

License

Notifications You must be signed in to change notification settings

Evavic44/sanity-nextjs-revalidation

Repository files navigation

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.

Live Preview

preview

Prerequisites

This template uses the following versions:

  • Nextjs: v14.0.4
  • next-sanity: v7.0.4
  • sanity: 3.21.3
  • React: v18

Important files and folders

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

Run project locally

  • clone repository
git clone https://github.com/Evavic44/sanity-nextjs-revalidation.git

cd sanity-nextjs-revalidation

npm install
  • Rename .env.example to .env

Update Env Variables

  • 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

About

A simple guide to illustrate how to setup on-demand revalidation in Sanity and Nextjs app directory

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published