A React hook for toggling between two values
npm install @react-hook/togglenpm i @react-hook/toggle
A React hook for toggling between two values
``jsx harmony
import useToggle from '@react-hook/toggle'
const Component = (props) => {
const [value, toggle] = useToggle(false, true)
return (
)
}
`
`ts`
function useToggle
off: Off,
on: On,
defaultValue: Off | On = off
): [Off | On, () => void]
| Argument | Type | Default | Required? | Description |
| ------------ | ---------- | ------- | --------- | ------------------------------------------------------------------ |
| off | Off | false | No | The value of the toggle in its off state |On
| on | | true | No | The value of the toggle in its on state |Off | On
| defaultValue | | off | No | The default value of the toggle, either the value of off or on` |
MIT