Evavic44 / sanity-nextjs-revalidation

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

Home Page:https://sanity-nextjs-revalidate.vercel.app

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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.

  • 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

https://sanity-nextjs-revalidate.vercel.app

License:MIT License


Languages

Language:TypeScript 95.5%Language:JavaScript 3.7%Language:CSS 0.7%