Skip to content

Latest commit

 

History

History
29 lines (22 loc) · 426 Bytes

use-toggle.md

File metadata and controls

29 lines (22 loc) · 426 Bytes

useToggle

A hook that toggle states.

Usage

import { useToggle } from '@mints/hooks';

const Example = () => {
  const [state, toggle] = useToggle('Hello', 'World');

  return (
    <div>
      <span>{state}</span>
      <span onClick={toggle}>Toggle</span>
    </div>
  );
};

API

useToggle = <T, U>(
  defaultState: T = false as T,
  reverseState?: U,
): [T | U, () => void]