Skip to content

Toggle Primitive

Slot Primitives

Types Primitives

@radix-ui/react-toggle


A button with a true or false state, which can be activated or deactivated by toggling.

Installation

Install @radix-ui/react-toggle

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

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

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

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

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

Usage

import * as React from 'react';
import { Text } from 'react-native';
import * as TogglePrimitive from '~/components/primitives/toggle';
function Example() {
const [isActive, setIsActive] = React.useState(false);
return (
<TogglePrimitive.Root pressed={isActive} onPressedChange={setIsActive}>
<Text>Bold</Text>
</TogglePrimitive.Root>
);
}

Props

Root

Extends Pressable props

PropTypeNote
pressedboolean
onPressedChange(val: boolean) => void
asChildboolean(optional)
disabledboolean(optional)