Skip to content

Checkbox Primitive

Hooks Primitives

Slot Primitives

Types Primitives

@radix-ui/react-checkbox


A box that is a checked (ticked) indicator when activated.

Installation

Install @radix-ui/react-checkbox

Terminal window
npx expo install @radix-ui/react-checkbox

Copy/paste the following code for web to ~/components/primitives/checkbox/checkbox.web.tsx

Copy/paste the following code for native to ~/components/primitives/checkbox/checkbox.tsx

Copy/paste the following code for types to ~/components/primitives/checkbox/types.ts

Copy/paste the following code for exporting to ~/components/primitives/checkbox/index.ts

Usage

import * as CheckboxPrimitive from '~/components/primitives/checkbox';
function Example() {
const [checked, setChecked] = React.useState(false);
return (
<CheckboxPrimitive.Root checked={checked} onCheckedChange={setChecked}>
<CheckboxPrimitive.Indicator style={{ height: 4, width: 4, backgroundColor: 'red'}} />
</CheckboxPrimitive.Root>
);
}

Props

Root

Extends Pressable props

PropTypeNote
checked*boolean
onCheckedChange*(checked: boolean) => void
disabledboolean(optional)

Indicator

Extends View props

PropTypeNote
forceMounttrue | undefined(optional)