Skip to content

useToggle

Hook that create toggle

state
high
test coverage
Last changed: 7 months ago

Installation

Library
CLI
Manual
typescript
import { useToggle } from '@siberiacancode/reactuse';

Usage

typescript
const [on, toggle] = useToggle();
// or
const [value, toggle] = useToggle(['light', 'dark'] as const);

Demo

Api

Parameters

NameTypeDefaultNote
values?Value[][false, true]The values to toggle

Type declaration

typescript
import type { SetStateAction } from 'react';

export type UseToggleReturn<Value> = readonly [Value, (value?: Value) => void];

Source

SourceDemo

Contributors

D
debabin
debabin
H
hywax
hywax

Released under the MIT License.