Skip to content

Latest commit

 

History

History
35 lines (25 loc) · 528 Bytes

useToggle.md

File metadata and controls

35 lines (25 loc) · 528 Bytes

useToggle

Tracks value of a boolean

Usage

import { useToggle } from 'use-haki';

const App = () => {
  const { on, toggle } = useToggle();

  return (
    <div>
      <span>{on && 'Hi there 👋'}</span>
      <button onClick={toggle}>toggle me 👀</button>
    </div>
  );
};

Reference

const { on, toggle } = useToggle(initialOn);
  • initialValue - initialOn by default is false
  • on - toggle state
  • toggle - function that toggle on state

Returns

  • toggle
  • on