Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

132
Views
Sanity.io reusable schema field types

I'm new to Sanity.io. I'm just wondering if there is a way that I can optimize my codes and reuse the fields in different schemas.

Im thinking something like this:

cars.ts:

export default {
    name: 'cars',
    title: 'Cars',
    type: 'document',
    fields: [vehicleName]
}

trucks.ts:

export default {
    name: 'trucks',
    title: 'Trucks',
    type: 'document',
    fields: [vehicleName]
}

vehicleName.ts:

export const vehicleName = {
    name: 'name',
    title: 'Name',
    type: 'string',
    validation: Rule => Rule.required()
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

    {
  title: 'Vehicle Names',
  name: 'vehicles',
  type: 'array',
  of: [
    {
      type: 'reference',
      to: [
        {type: 'cars'},
        {type: 'trucks'}
      ]
    }
  ]
}

You can use references to access the cars and trucks in as many different schemas as you want making your code reusable

export default {
    name: 'trucks',
    title: 'Trucks',
    type: 'array',
    fields: [
    {
      title: 'Names',
      name: 'names',
      type: 'reference',
      to: [{type: 'vechicleName'}]
    }
  ]
}

Sanity is bi-directional

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!