Skip to content

Latest commit

 

History

History
24 lines (19 loc) · 619 Bytes

useSet.md

File metadata and controls

24 lines (19 loc) · 619 Bytes

useSet

React state hook that tracks a Set.

Usage

import {useSet} from 'react-use';

const Demo = () => {
  const [set, { add, has, remove, reset }] = useSet(new Set(['hello']));

  return (
    <div>
      <button onClick={() => add(String(Date.now()))}>Add</button>
      <button onClick={() => reset()}>Reset</button>
      <button onClick={() => remove('hello')} disabled={!has('hello')}>
        Remove 'hello'
      </button>
      <pre>{JSON.stringify(Array.from(set), null, 2)}</pre>
    </div>
  );
};