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

Trouble adding reference to array causing crashes in Sanity UI

6 replies
Last updated: Jun 23, 2023
I’m trying to add a reference to an array and it mostly works fine and then days later it crashes and I can no longer use the component, so i restructured it to match the other object i’m adding to the array and it still seems to crash and I cannot pinpoint the cause of failure. anytime I try and add a reference to the array it searches and then hits me with a :
Error: Objects are not valid as a React child (found: object with keys {$$typeof, render}). If you meant to render a collection of children, use an array instead.
Jun 23, 2023, 7:20 AM
    defineField({
      name: 'products',
      title: 'Products',
      description: 'Product landings will be pulled automatically unless specified here',
      type: 'array',
      of: [
        {
          type: 'productLandingWithVariant',
        },
        {
          type: 'productBundle',
        }
      ]
    }),
Jun 23, 2023, 7:20 AM
the productlandingwithvariant is fine, I originally had productBundle as an inline object (this is not a graphql build) but i thought that might be why it was failing
Jun 23, 2023, 7:21 AM
so i moved productBundle to:

export default defineField({
  name: 'productBundle',
  title: 'Product Bundle',
  type: 'object',
  icon: TagIcon,
  fields: [
    defineField({
      name: 'bundleProduct',
      type: 'reference',
      to: [{type: 'bundle'}],
      weak: true,
    }),
  ],
  preview: {
    select: {

      title: 'bundle.title',
  
    },
    prepare(selection) {
      const {
        title,
      } = selection

      return {
        title: title,
      }
    },
  },
})
Jun 23, 2023, 7:21 AM
and it still causes the whole sanity ui to crash
Jun 23, 2023, 7:22 AM
lil video where i quickly show it doesn’t crash on the other object that is essentially the same
Jun 23, 2023, 7:31 AM
lol. okay it’s apparently mad at the icon. I think i fixed it finally
Jun 23, 2023, 7:45 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?