Nesting document types and using Sanity with Next.js discussed in Slack thread
21 replies
Last updated: Jan 12, 2023
P
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
Take a look at this resource https://www.sanity.io/docs/structure-builder-introduction
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
P
Thank you so much, I will try this out shortly.
Jan 11, 2023, 11:08 AM
P
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 srcfolder?
Jan 11, 2023, 9:33 PM
I typically create a next project then install sanity into a dir titled
/adminbut you can use
/studiotheres other ways to do it but I found this to work very easy
Jan 11, 2023, 9:34 PM
P
user G
I see, then I understood it right, I wasn't sure of it. THank you for confirmingJan 11, 2023, 9:35 PM
P
Great, understood. Thank you
Jan 11, 2023, 9:36 PM
P
user G
I finally set up the folders in a structure, but I get a useContexterror when running
next devcommand. 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
reactand
react-domlibraries 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
Take a look at the
package.jsonscripts and in the
next.config.jsis 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
https://www.sanity.io/guides/sanity-nextjs-tailwindcss
Jan 11, 2023, 11:38 PM
P
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 startand then runs build commands for next
Jan 11, 2023, 11:42 PM
P
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
P
So I won't have dplicates or something
Jan 11, 2023, 11:43 PM
P
Basically, I installed nextjs with
npm create nextjs@latestthen 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
P
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
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.