Switch Primitive
A control enabling the user to switch between a checked and unchecked state.
Installation
Install the component via your command line.
Install @radix-ui/react-switch
Copy/paste the following code for web to ~/components/primitives/switch/switch.web.tsx
Copy/paste the following code for native to ~/components/primitives/switch/switch.tsx
Copy/paste the following code for types to ~/components/primitives/switch/types.ts
Copy/paste the following code for exporting to ~/components/primitives/switch/index.ts
Copy/paste the following code for native to ~/components/primitives/switch/index.tsx
Copy/paste the following code for types to ~/components/primitives/switch/types.ts
Usage
Props
Root
Extends Pressable
props
Prop | Type | Note |
---|---|---|
checked | boolean | |
onCheckedChange | (checked: boolean) => void | |
disabled | boolean | (optional) |
asChild | boolean | (optional) |
onKeyDown | (ev: React.KeyboardEvent) => void | Web Only (optional) |
Thumb
Extends View
props
Prop | Type | Note |
---|---|---|
asChild | boolean | (optional) |