🔮 Sanity Create is here. Writing is reinvented. Try now, no developer setup

Setting up Sanity with React project and resolving an error.

8 replies
Last updated: Aug 7, 2021
Getting help with setting up project with Sanity and React:I created my React project in a folder using npm create-react-app portfolio. Where do I install Sanity? In the same folder? I tried this before and it just mixed the two things together and created a mess. Where should I enter:
npm install -g @sanity/cli && sanity init ?
Aug 6, 2021, 11:01 PM
npm install -g @sanity/cli
can be run in any folder.
I believe
Kapehe runs
sanity init
from the root folder of her project. When it prompts for “Project output path” the default should put your studio in a subfolder.
Aug 6, 2021, 11:06 PM
So I should install Sanity inside a sub-folder of the React project?
Aug 6, 2021, 11:21 PM
Yes, that’s one way to do it. Another is to install it outside the React project (i.e., as a sibling to the React folder). I think Kap does the former so that’s a good plan if you want to follow that tutorial.
Aug 6, 2021, 11:22 PM
So far so good! Will let you know how it turns out. THANK YOU!
Aug 7, 2021, 12:51 AM
Things went well until near the end when I got stuck here. I've gone through teh video twice and I' not sure what I am missing.
Aug 7, 2021, 6:24 AM
That error would happen if a post is missing a slug, since it’s looking for a property called
current
inside of
slug
but
slug
is undefined (i.e., doesn’t exist). There are a few ways to solve this, including short-circuiting (which Kap did a few lines above with
postData
) and optional chaining , but a quick fix should be to add a slug to all your posts.
Aug 7, 2021, 3:56 PM
That error would happen if a post is missing a slug, since it’s looking for a property called
current
inside of
slug
but
slug
doesn’t exist. There are a few ways to solve this, including short-circuiting (which Kap did a few lines above with
postData
) and optional chaining , but a quick fix should be to add a slug to all your posts.
Aug 7, 2021, 3:56 PM
Thanks! I will try it now.
Aug 7, 2021, 3:57 PM

Sanity– build remarkable experiences at scale

Sanity is a modern 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?