šŸ‘‹ Next.js Conf 2024: Come build, party, run, and connect with us! See all events

How to get Values from the Parent Component of my Custom Input Component

2 replies
Last updated: Dec 22, 2021
Hi! I'd like to get value's from the parent component of my custom input component. However I get stuck at the withDocument HOC, because I'm using the custom input component in an array of which I want the index in my custom input.
{
  name: "filters",
  title: "Filters",
  type: "array",
  of: [
    {
      type: "object",
      name: "category",
      fields: [
        {
          type: "reference",
          name: "category",
          to: [{ type: "category" }],
        },
        {
          name: "productFilters",
          type: "string",
          inputComponent: ProductFilter,
        },
      ],
    },
  ],
}
Dec 21, 2021, 4:00 PM
In your case, you'd be able to find the index of the parent
category
object inside of the
filters
array using the
withDocument
HOC like so:
const index = props.document.filters.indexOf(parent)
Does this component need to be reused in other places though? If so, we'd need to figure out a more flexible way of accessing it!
Dec 21, 2021, 6:43 PM
Thanks! This is what I needed āœ…
Dec 22, 2021, 10:36 AM

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?