Or get started using the CLI
Combine Next.js's getStaticProps()
with Sanity's native JavaScript client and connect your front end to a user-friendly, fully-featured CMS in the time it takes to make coffee.
- Deploy an instance of Sanity studio (
npm create sanity@latest
) - Create a Next.js app, and begin fetching data for static site generation in a tiny amount of code.
- Iterate on blazing-fast content at record speed.
This is all the code you need. Seriously.
const sanityClient = require("@sanity/client");
export const client = sanityClient({
projectId: process.env.NEXT_PUBLIC_SANITY_ID,
dataset: "production",
useCdn: true,
});
export default function Home({ post }) {
return (
<div>{post.content}</div>
);
}
export async function getStaticProps({ params }) {
//use Sanity's home-grown query language GROQ to build anything you can imagine
const post = await client.fetch('*[_type == "post"][0]');
return {
props: {
post,
},
};
}