Skip to content

useSwitch API

API reference docs for the useSwitch hook. Learn about the input parameters and other APIs of this exported module.

Demos

For examples and details on the usage of this React hook, visit the demo pages:

Import

import useSwitch from '@mui/base/useSwitch';


The basic building block for creating custom switches.

Parameters

NameTypeDefaultDescription
checkedboolean
If true, the component is checked.
defaultCheckedboolean
The default checked state. Use when the component is not controlled.
disabledboolean
If true, the component is disabled.
onBlurReact.FocusEventHandler
onChangeReact.ChangeEventHandler<HTMLInputElement>
Callback fired when the state is changed.
onFocusReact.FocusEventHandler
onFocusVisibleReact.FocusEventHandler
readOnlyboolean
If true, the component is read only.
requiredboolean
If true, the input element is required.

Return value

NameTypeDefaultDescription