Nesting document types and using Sanity with Next.js discussed in Slack thread

21 replies
Last updated: Jan 12, 2023
Hello, Is it possible to nest multiple document types inside one another in the Studio? Like to make a data structure as a tree.
Jan 10, 2023, 11:10 PM
Jan 10, 2023, 11:32 PM
You can’t exactly nest a document inside of a document, but you can effectively do the same thing by using references! This will allow you to create a flexible hierarchy that will be easily query-able. And as Brian pointed out, you can use a custom desk structure to visually display this in your Studio.
Jan 11, 2023, 5:17 AM
Thank you so much, I will try this out shortly.
Jan 11, 2023, 11:08 AM
user M
Hello Miss, Can you tell me, if I want to use Sanity with Next.js, I should install Next.js first then install Sanity in the Next.js's
src
folder?
Jan 11, 2023, 9:33 PM
I typically create a next project then install sanity into a dir titled
/admin
but you can use
/studio
theres other ways to do it but I found this to work very easy
Jan 11, 2023, 9:34 PM
user G
I see, then I understood it right, I wasn't sure of it. THank you for confirming
Jan 11, 2023, 9:35 PM
/root 
   /pages
   /components
   /public
   /admin *this is where I install sanity
Jan 11, 2023, 9:35 PM
^ how my files are usually set up
Jan 11, 2023, 9:36 PM
Great, understood. Thank you
Jan 11, 2023, 9:36 PM
user G
I finally set up the folders in a structure, but I get a
useContext
error when running
next dev
command. I checked for possible problems, like version mismatch. Versions are OK. In the demo next.js pages folder, there are no componenets which explicitly use hooks, so I guess that's not the problem either. Lastly, maybe the problem is that there are two
react
and
react-dom
libraries one for next.js and one for the sanity studio. But these two shouldn't interfere wiht one another. So, what do you suggest? How could I solve this?
Jan 11, 2023, 11:34 PM
I put together this repo a while back for my self to use as a template https://github.com/briannelson95/sanity-next-client-example
Take a look at the
package.json
scripts and in the
next.config.js
is where the routing get handled to use the studio on domain .com/admin
Jan 11, 2023, 11:37 PM
This is for v2 btw but so far with v3 I haven’t seen any major problems around set up
Jan 11, 2023, 11:38 PM
Here is the blog I followed to set this up
https://www.sanity.io/guides/sanity-nextjs-tailwindcss
Jan 11, 2023, 11:38 PM
Sorry if that doesn’t help, I haven’t ran into the useContext error before
Jan 11, 2023, 11:39 PM
Oh, all right, no worries. I am going to look into this in the morning then. Thank you for your time.
Jan 11, 2023, 11:40 PM
No problem, I basically treat the 2 directories as separate project, each has its on package.json and on build, it directs the server to /admin then run
sanity start
and then runs build commands for next
Jan 11, 2023, 11:42 PM
Yep, that is clear to me too, maybe i should delete all npm packages from my laptop and reinstall which are necessary
Jan 11, 2023, 11:43 PM
So I won't have dplicates or something
Jan 11, 2023, 11:43 PM
Yea might be worth a try or at least form the project
Jan 11, 2023, 11:43 PM
Basically, I installed nextjs with
npm create nextjs@latest
then inside the admin folder I installed sanity separately. It's fine, both work seamlessly, but Nextjs is bugging me. Anyway, thank you for replying. Have a good one. 🙂
Jan 11, 2023, 11:44 PM
Hello, finally I managed to do what I wanted. It's super cool. Thanks for your support.
Jan 12, 2023, 3:46 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?