OneScript

Toggle

Switch a boolean value on or off.

A controlled switch. Pass the current isOn value and update it from onChange. children is the label.

import { Toggle, useState } from "onescript/views"

function WifiToggle() {
  const [enabled, setEnabled] = useState(true)
  return (
    <Toggle
      isOn={enabled}
      onChange={setEnabled}
    >
      Wi-Fi
    </Toggle>
  )
}
PropTypeDescription
isOnbooleanCurrent value.
onChange(isOn: boolean) => voidRuns when the user flips the switch.
childrenViewChildThe label.

Use toggleStyle to show it as a button and labelsHidden to hide the label. Also accepts Modifiers. It is only available in App and Action view sessions; widgets reject it with an unsupported view type error.

How is this guide?

Last updated on