1 | /**
|
2 | * Create a state setter pair for a boolean value that can be "switched".
|
3 | * Unlike `useState(false)`, `useToggleState` will automatically flip the state
|
4 | * value when its setter is called with no argument.
|
5 | *
|
6 | * @param initialState The initial boolean value
|
7 | * @returns A tuple of the current state and a setter
|
8 | *
|
9 | * ```jsx
|
10 | * const [show, toggleShow] = useToggleState(false)
|
11 | *
|
12 | * return (
|
13 | * <>
|
14 | * <button onClick={() => toggleShow()}>
|
15 | * Toggle
|
16 | * <button>
|
17 | *
|
18 | * {show && <strong>Now you can see me</strong>}
|
19 | * </>
|
20 | * )
|
21 | *
|
22 | * ```
|
23 | */
|
24 | export default function useToggleState(initialState?: boolean): [boolean, (value?: boolean | undefined) => void];
|