New user seeks help with configuring Sanity client in Next.js app.

6 replies
Last updated: Jun 10, 2023
This looks like it’s coming from where you’ve configured your client on your front end, rather than from within the Studio code. Can you please post the code snippet where you’ve instantiated your client? Something like:

import { createClient } from '@sanity/client';

export const client = createClient({
  projectId: 'abcd1234',
  dataset: 'production',
  apiVersion: '2023-06-10',
  useCdn: true,
});
Jun 10, 2023, 2:44 PM
Hi User, thank you for offering your help. I'm currently new to Sanity and I'm working on building an E-Commerce app with Sanity and Next.js. I followed the steps to install the Next.js npm package first and then created the project from the web of sanity. Then, I installed the npm package for Sanity that was provided after creating the project.
Since I'm new to Sanity, I'm a bit confused about the code snippet you mentioned. I'm not sure where exactly I need to instantiate the client as you described. Could you please provide more guidance or clarification on how to integrate Sanity into my application and create the client?

Thank you for your assistance, I really appreciate it!
Jun 10, 2023, 2:59 PM
Welcome to the community!
In your Next.js code, you will use the Sanity Client to pull in your content from the Content Lake (essentially the Sanity data store). That client will need to be configured with your projectId, dataset, etc., so that it knows where to source from.

Is there a particular guide or tutorial you’re following? I can take a look and find where the client is configured.
Jun 10, 2023, 3:06 PM
https://youtu.be/4mOkFXyxfsU is a 1 year old video which I am using to learn about Sanity. But the difference is that I am using all the latest versions, not the old ones.
Thank you User for helping, I will check out Content Lake.
Jun 10, 2023, 3:32 PM
Looks like they start that setup at around the 40:36 mark . You’ll now import
{ createClient } from '@sanity/client';
and will use that function in place of
sanityClient
, but the config looks to be the same. Make sure you’re specifying `projectId`—case matters.
Jun 10, 2023, 3:40 PM
You are awesome User, while following the video I will do as you say and import createClient. 🤩 👍
Jun 10, 2023, 4:03 PM

Sanity– build remarkable experiences at scale

The Sanity Composable Content Cloud is the headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?

Categorized in