Getting context in custom input components in Sanity v3

13 replies
Last updated: Jan 2, 2023
Hello! It seems that the
parent
object is no longer sent to custom input component in sanity v3. How would I go about getting context about the current object in the new version? The docs i can find (https://www.sanity.io/guides/your-first-input-component-for-sanity-studio-v3 ) doesn't mention anything about it. In v2 i could access it via
props.parent
Jan 2, 2023, 2:30 PM
Hi thanks for your message. I havnt accessed the link you shared yet. Do you think i should continue installing v3 rather 2?
Jan 2, 2023, 3:07 PM
const docId = String(useFormValue(["_id"]));
Jan 2, 2023, 3:11 PM
Hi, I did not find any documentation on this yet, but I’m using
useFormValue
. For example getting the _id of the document could be done like this:
import { useFormValue } from "sanity";
const docId = String(useFormValue(["_id"])); 
Jan 2, 2023, 3:13 PM
Thanks
user U
! That did the trick. I wanted to access the parent in a nested object inside the document, but I was able to get that from using
useFormValue(props.path.slice(0, -1))
(slice to remove the last element from the array, as without it I would just get the custom components value)
Jan 2, 2023, 3:22 PM
user H
With this fixed, I was able to migrate all my things to v3 relatively easily, even with a couple of custom plugins and components. I will say the docs are still somewhat lacking, but it's much much better than when it was in beta 🙂
Jan 2, 2023, 3:24 PM
Thanks Ill give it go.
Jan 2, 2023, 3:30 PM
Ok as i mentioned. I am pretty new to this so the document means nothing to me. What i mean is where is that document? is it something that has been written by yourself? Sorry to sound bit thick. However thanks all the same so far.
Jan 2, 2023, 4:21 PM
user H
no worries, be nice to yourself: nobody sounds thick and there are no stupid questions :sanity_with_3_hearts:I am a bit unsure, which document you mean.
As you know, you have to kinds of types: document and objects. Where are you stuck in the migration?
Jan 2, 2023, 4:27 PM
Hi Saskia, At present i'm not to sure where to look or to resolve the error i got
Jan 2, 2023, 4:47 PM
[plugin:vite:css] [postcss] Cannot read properties of undefined (reading 'config')
    at getTailwindConfig (/Users/neillwhite/builds/portfolio-nw/node_modules/tailwindcss/lib/lib/setupTrackingContext.js:84:63)
    at /Users/neillwhite/builds/portfolio-nw/node_modules/tailwindcss/lib/lib/setupTrackingContext.js:96:92
    at /Users/neillwhite/builds/portfolio-nw/node_modules/tailwindcss/lib/processTailwindFeatures.js:46:11
    at plugins (/Users/neillwhite/builds/portfolio-nw/node_modules/tailwindcss/lib/index.js:38:63)
    at LazyResult.runOnRoot (/Users/neillwhite/builds/portfolio-nw/sanity/node_modules/postcss/lib/lazy-result.js:339:16)
    at LazyResult.runAsync (/Users/neillwhite/builds/portfolio-nw/sanity/node_modules/postcss/lib/lazy-result.js:393:26)
    at LazyResult.async (/Users/neillwhite/builds/portfolio-nw/sanity/node_modules/postcss/lib/lazy-result.js:221:30)
    at LazyResult.then (/Users/neillwhite/builds/portfolio-nw/sanity/node_modules/postcss/lib/lazy-result.js:206:17)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (node:internal/process/task_queues:96:5

Jan 2, 2023, 4:47 PM
This is another matter, did you post this in help already?
Jan 2, 2023, 4:48 PM
Oh yes I did already answer in there. Please dont crosspost, because it makes our work harder 😉 https://sanity-io-land.slack.com/archives/C9Z7RC3V1/p1672668729388019
Jan 2, 2023, 4:50 PM
oh yes i did apologies. Ill head over to your link. Hopefully i can get somewhere with that
Jan 2, 2023, 4:54 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?