Rendyn

Component library

189 components

Interaction

Switch

Switch is a controlled binary control: checked and onCheckedChange define its state.

Interactive exampleReact Tailwind CSS

Practical React example

Let a person toggle a notification preference and show whether the preference is enabled.

Before you copy and paste

Keep the example in the React rendering environment required by the imported component. Copy components/motion/switch.tsx and its returned support files from the Code tab; preserve the project-relative paths.

Listed package dependencies: clsx, motion, react, tailwind-merge.

Use the Code tab for the component files and installation instructions, then adapt the imports in this example to your project.

Let a person toggle a notification preference and show whether the preference is enabled

// Usage adapted from beUI's pinned MIT source.
// Copyright (c) 2026 Saurabh Chauhan. See ./LICENSES.md.
"use client";

import { useState } from "react";
import { Switch } from "@/components/motion/switch";

export function SwitchPreview() {
  const [on, setOn] = useState(true);
  return (
    <div className="flex flex-col gap-3">
      <Switch checked={on} onCheckedChange={setOn} label="Enable notifications" />
      <Switch checked={false} onCheckedChange={() => {}} label="Off" />
      <Switch checked disabled onCheckedChange={() => {}} label="Disabled" />
    </div>
  );
}

Usage example adapted from beUI's pinned MIT source. Retain the source licence notices when copying.

Keep checked in parent state. If the setting is saved remotely, show pending and failure feedback and reconcile the displayed value with the saved preference.

Customization

SwitchProps.checked
Required; boolean.
SwitchProps.onCheckedChange
Required; (checked: boolean) => void.
SwitchProps.disabled
Optional; boolean.
SwitchProps.label
Optional; string.
SwitchProps.ariaLabel
Optional; string.
SwitchProps.className
Optional; string.

Integration notes

  • Provide a persistent label describing the setting, not just its current value.
  • Disabling the switch only affects the UI; the server must still authorize preference changes.

Component source: beUI documentation . These examples describe the version imported into Rendyn. Upstream APIs may have changed; retain the source licence notices when adapting the code.

Better with your agent

Give your agent taste.

The best way to use Rendyn is through MCP. Let your agent find the right component, compare previews and bring the source into your project.

All components are free. Sign up only to connect MCP.

Connect to MCP