Switch
Switches are UI elements that let users choose between two states—most commonly on/off.
useSwitch API
Import
import { useSwitch } from '@mui/base/useSwitch';
// or
import { useSwitch } from '@mui/base';
Name | Type | Default | Description |
---|---|---|---|
checked | boolean | - | If |
defaultChecked | boolean | - | The default checked state. Use when the component is not controlled. |
disabled | boolean | false | If |
inputRef | React.Ref<HTMLInputElement> | - | Ref to the underlying input element. |
name | string | - | Name of the underlying input element. |
onChange | React.ChangeEventHandler<HTMLInputElement> | - | Callback fired when the state is changed. |
readOnly | boolean | false | If |
required | boolean | false | If |
Name | Type | Default | Description |
---|---|---|---|
checked | boolean | - | If |
getButtonProps | (externalProps?: React.ComponentPropsWithRef<'button'>) => React.ComponentPropsWithRef<'button'> | - | Resolver for the button element's props. |
getInputProps | (externalProps?: React.ComponentPropsWithRef<'input'>) => React.ComponentPropsWithRef<'input'> | - | Resolver for the input element's props. |