Sanity logosanity.ioAll Systems Operational© Sanity 2026
Change Site Theme
Sanity logo

Documentation

    • Overview
    • Platform introduction
    • Next.js quickstart
    • Nuxt.js quickstart
    • Astro quickstart
    • React Router quickstart
    • Studio quickstart
    • Build with AI
    • Content Lake
    • Functions
    • APIs and SDKs
    • Visual Editing
    • Blueprints
    • Platform management
    • Dashboard
    • Studio
    • Canvas
    • Media Library
    • App SDK
    • Content Agent
    • HTTP API
    • CLI
    • Libraries
    • Specifications
    • Changelog
    • User guides
    • Developer guides
    • Courses and certifications
    • Join the community
    • Templates
Studio
Overview

  • Setup and development

    Installation
    Project Structure
    Development
    Hosting and deployment
    Embedding Sanity Studio
    Upgrading Sanity Studio
    Environment Variables
    Using TypeScript in Sanity Studio
    Understanding the latest version of Sanity

  • Configuration

    Introduction
    Workspaces
    Schema and forms
    Conditional fields
    Field Groups
    List Previews
    Connected Content
    Validation
    Initial Value Templates
    Cross Dataset References
    Sort Orders
    Visual editing and preview
    Incoming reference decoration

  • Block Content (Portable Text)

    Introduction
    Configure the Portable Text Editor
    Customize the Portable Text Editor
    Create a Portable Text behavior plugin
    Add Portable Text Editor plugins to Studio
    Common patterns
    Standalone Portable Text Editor

  • Studio customization

    Introduction
    Custom component for Sanity Studio
    Custom authentication
    Custom asset sources
    Diff components
    Form Components
    How form paths work
    Icons
    Favicons
    Localizing Sanity Studio
    New Document Options
    Studio Components
    Studio search configuration
    Focus and UI state in custom inputs
    Real-time safe patches for input components
    Sanity UI
    Studio Tools
    Create a custom Studio tool
    Tools cheat sheet
    Theming

  • Workflows

    The Dashboard tool for Sanity Studio
    Add widgets to dashboard
    Document actions
    Release Actions
    Custom document badges
    Localization
    Content Releases Configuration
    Enable and configure Comments
    Configuring Tasks
    Scheduled drafts
    Scheduled publishing (deprecated)
    Manage notifications

  • Structure builder

    Introduction
    Get started with Structure Builder API
    Override default list views
    Create a link to a single edit page in your main document type list
    Manually group items in a pane
    Dynamically group list items with a GROQ filter
    Create custom document views with Structure Builder
    Cheat sheet
    Structure tool
    Reference

  • Plugins

    Introduction
    Installing and configuring plugins
    Developing plugins
    Publishing plugins
    Internationalizing plugins
    Reference
    Official plugins repo

  • AI Assist

    Installation
    Translation
    Custom field actions
    Field action patterns

  • User guides

    Comments
    Task
    Copy and paste fields
    Compare document versions
    Content Releases
    Scheduled drafts
    View incoming references
    Common keyboard shortcuts

  • Studio schema reference

    Studio schema configuration
    Array
    Block
    Boolean
    Cross Dataset Reference
    Date
    Datetime
    Document
    File
    Geopoint
    Global Document Reference
    Image
    Number
    Object
    Reference
    Slug
    Span
    String
    Text
    URL

  • Studio reference

    Asset Source
    Configuration
    Document
    Document Badges
    Document Actions
    Form
    Form Components
    Hooks
    Structure tool
    Studio Components Reference
    Tools
    Initial Value Templates
    Studio API reference

On this page

Previous

Sort Orders

Next

Introduction

Was this page helpful?

On this page

  • Add an inline incoming reference decoration
  • Create and reference new documents
  • Add reference to existing documents
  • Create custom actions
  • Support cross-dataset references
StudioLast updated February 4, 2026

Incoming reference decoration

Display incoming references directly in a document's form, without storing the data as part of the document.

Studio's inline incoming references feature allows you to define a component that will display any incoming references to the current document.

Unlike a field containing an array of references, these incoming references are not part of the document and will display automatically when new references are made.

Prerequisites:

  • Studio v5.8.0 or later is required to use incoming reference fields.

Add an inline incoming reference decoration

To add incoming references to a field in your schema, import and use the defineIncomingReferenceDecoration helper.

import {defineType} from 'sanity'
import {defineIncomingReferenceField} from 'sanity/structure'

export default defineType({
  name: 'author',
  type: 'document',
  renderMembers: (members) => {
   return [
     ...members,  // Places the decoration after all existing fields.
     defineIncomingReferenceDecoration({
       name: 'incomingReferences',
       title: 'Incoming references',
       types: [{type: 'author'}],
     }),
   ]
  },
 fields: [],
})

This adds a component into the document that looks like the following:

Loading...

Create and reference new documents

You can allow the "Create" button to pre-populate a new document with a reference to the source document.

This feature can leverage the initialValue of a new document to set the reference. On the schema for the referencing document type, use the isIncomingReferenceCreation helper to check if an incoming reference field is creating the new document. Then pass in the reference to the appropriate field. In this example, the book document type references the author type.

import {defineType} from 'sanity'
import {isIncomingReferenceCreation} from 'sanity/structure'

export defineType({
  name: "book",
  fields: [
    // ...
  ],
   initialValue: (params) => {
    return {
      author: isIncomingReferenceCreation(params) ? params.reference : undefined,
    }
  },
)

Add reference to existing documents

If you have existing documents that you want to search/assign to the current document, use the onLinkDocument option.

import {defineType} from 'sanity'
import {defineIncomingReferenceDecoration} from 'sanity/structure'

export default defineType({
  name: 'author',
  type: 'document',
  renderMembers: (members) => {
   return [
     ...members, 
     defineIncomingReferenceDecoration({
      name: 'booksCreatedByThisAuthor',
      options: {
        types: [{type: 'book'}],
        onLinkDocument: (document, reference) => {
          return {
            ...document,
            author: reference, // <-- the reference is passed to the document
          }
        },
      },
    }),
   ]
  },
  fields: [
    defineField({type: "string", name: "name"}),
   // ...
  ]
})

Create custom actions

You can also pass custom actions to the incoming reference field. This format is similar to document actions, but occurs in the defineIncomingReferenceDecoration helper. This example creates an action in ReferenceActions.tsx and applies it in the options.actions array.

import {defineType} from 'sanity'
import {defineIncomingReferenceDecoration} from 'sanity/structure'
import {RemoveReferenceAction} from './ReferenceActions'

export default defineType({
  name: 'author',
  type: 'document',
  renderMembers: (members) => {
   return [
     ...members,  
     defineIncomingReferenceDecoration({
       name: 'incomingReferences',
       title: 'Incoming references',
       types: [{type: 'author'}],
       actions: [RemoveReferenceAction]
     }),
   ]
  },
 fields: [],
})
import {type IncomingReferenceAction} from 'sanity/structure'
import {getDraftId} from 'sanity'
import {useState} from 'react'

export const RemoveReferenceAction: IncomingReferenceAction = ({document, getClient}) => {
  const [dialogOpen, setDialogOpen] = useState(false)
  const client = getClient({apiVersion: '2025-10-01'})

  return {
    label: 'Remove reference',
    icon: TrashIcon,
    tone: 'critical',
    dialog: dialogOpen
      ? {
          type: 'confirm',
          message: 'Are you sure you want to remove the reference?',
          onCancel: () => setDialogOpen(false),
          onConfirm: async () =>
            await client.createOrReplace({
              ...document,
              _id: getDraftId(document._id),
              author: undefined, // Removes the reference from the document
            }),
        }
      : null,
    onHandle: () => setDialogOpen(true),
  }
}

Support cross-dataset references

Cross-dataset references are also supported. You'll need to supply additional details as shown below.

import {defineType} from 'sanity'
import {defineIncomingReferenceDecoration} from 'sanity/structure'

export default defineType({
  name: 'author',
  type: 'document',
  renderMembers: (members) => {
   return [
     ...members,
     defineIncomingReferenceDecoration({
       name: 'incomingReferencesCrossDataset',
       title: 'Incoming references CrossDataset',
        types: [
          {
            type: 'book',
            dataset: 'test-us',
            title: 'Book in test-us dataset',
            studioUrl: ({id, type}) => {
              return type ? `/us/intent/edit/id=${id};type=${type}` : null
            },
            preview: {
              select: {title: 'title', media: 'coverImage', subtitle: 'publicationYear'},
            },
          },
        ]
     }),
   ]
  },
 fields: [],
})
  • Article
  • Changelog
    New
import {defineType} from 'sanity'
import {defineIncomingReferenceField} from 'sanity/structure'

export default defineType({
  name: 'author',
  type: 'document',
  renderMembers: (members) => {
   return [
     ...members,  // Places the decoration after all existing fields.
     defineIncomingReferenceDecoration({
       name: 'incomingReferences',
       title: 'Incoming references',
       types: [{type: 'author'}],
     }),
   ]
  },
 fields: [],
})
Incoming reference field studio interface
import {defineType} from 'sanity'
import {isIncomingReferenceCreation} from 'sanity/structure'

export defineType({
  name: "book",
  fields: [
    // ...
  ],
   initialValue: (params) => {
    return {
      author: isIncomingReferenceCreation(params) ? params.reference : undefined,
    }
  },
)
import {defineType} from 'sanity'
import {defineIncomingReferenceDecoration} from 'sanity/structure'

export default defineType({
  name: 'author',
  type: 'document',
  renderMembers: (members) => {
   return [
     ...members, 
     defineIncomingReferenceDecoration({
      name: 'booksCreatedByThisAuthor',
      options: {
        types: [{type: 'book'}],
        onLinkDocument: (document, reference) => {
          return {
            ...document,
            author: reference, // <-- the reference is passed to the document
          }
        },
      },
    }),
   ]
  },
  fields: [
    defineField({type: "string", name: "name"}),
   // ...
  ]
})
import {defineType} from 'sanity'
import {defineIncomingReferenceDecoration} from 'sanity/structure'
import {RemoveReferenceAction} from './ReferenceActions'

export default defineType({
  name: 'author',
  type: 'document',
  renderMembers: (members) => {
   return [
     ...members,  
     defineIncomingReferenceDecoration({
       name: 'incomingReferences',
       title: 'Incoming references',
       types: [{type: 'author'}],
       actions: [RemoveReferenceAction]
     }),
   ]
  },
 fields: [],
})
import {type IncomingReferenceAction} from 'sanity/structure'
import {getDraftId} from 'sanity'
import {useState} from 'react'

export const RemoveReferenceAction: IncomingReferenceAction = ({document, getClient}) => {
  const [dialogOpen, setDialogOpen] = useState(false)
  const client = getClient({apiVersion: '2025-10-01'})

  return {
    label: 'Remove reference',
    icon: TrashIcon,
    tone: 'critical',
    dialog: dialogOpen
      ? {
          type: 'confirm',
          message: 'Are you sure you want to remove the reference?',
          onCancel: () => setDialogOpen(false),
          onConfirm: async () =>
            await client.createOrReplace({
              ...document,
              _id: getDraftId(document._id),
              author: undefined, // Removes the reference from the document
            }),
        }
      : null,
    onHandle: () => setDialogOpen(true),
  }
}
import {defineType} from 'sanity'
import {defineIncomingReferenceDecoration} from 'sanity/structure'

export default defineType({
  name: 'author',
  type: 'document',
  renderMembers: (members) => {
   return [
     ...members,
     defineIncomingReferenceDecoration({
       name: 'incomingReferencesCrossDataset',
       title: 'Incoming references CrossDataset',
        types: [
          {
            type: 'book',
            dataset: 'test-us',
            title: 'Book in test-us dataset',
            studioUrl: ({id, type}) => {
              return type ? `/us/intent/edit/id=${id};type=${type}` : null
            },
            preview: {
              select: {title: 'title', media: 'coverImage', subtitle: 'publicationYear'},
            },
          },
        ]
     }),
   ]
  },
 fields: [],
})