Skip to main content
Primitive is a collection of low-level components that render basic HTML elements. Each primitive supports an asChild prop for composition using the Slot pattern, allowing you to merge props and refs with a child element.

Installation

Available Primitives

The following primitive elements are available:
  • Primitive.a
  • Primitive.button
  • Primitive.div
  • Primitive.form
  • Primitive.h2
  • Primitive.h3
  • Primitive.img
  • Primitive.input
  • Primitive.label
  • Primitive.li
  • Primitive.nav
  • Primitive.ol
  • Primitive.p
  • Primitive.select
  • Primitive.span
  • Primitive.svg
  • Primitive.ul

Props

Each primitive accepts all standard HTML attributes for its element type, plus:
boolean
When true, the primitive will merge its props and ref with its immediate child element instead of rendering its own element. This enables powerful composition patterns.Default: false

Usage

Basic Usage

Using asChild for Composition

Custom Button Component

Polymorphic Component Pattern

Type Definitions

Utilities

dispatchDiscreteCustomEvent

A utility function for dispatching custom events within discrete React events while ensuring proper batching behavior.

Usage

When to Use

Use Primitives when:
  • Building component libraries with consistent base elements
  • You need the asChild composition pattern
  • Creating polymorphic components that can render as different elements
  • Building accessible components that merge props and refs correctly

Notes

The asChild prop uses the Slot pattern from @radix-ui/react-slot. When enabled, the Primitive merges its props and ref with the immediate child element instead of rendering its own DOM node.
Primitives automatically set a symbol on the window object (window[Symbol.for('radix-ui')]) to help with debugging and detecting Radix UI components in the browser.
The dispatchDiscreteCustomEvent utility uses ReactDOM.flushSync to ensure custom events dispatched within discrete events (like clicks) are properly batched by React. This prevents unexpected batching behavior in React 18+.