@tdukart/use-state-set
TypeScript icon, indicating that this package has built-in type declarations

0.1.1 • Public • Published

use-state-set

A convenience React hook to use JS Sets in a React state.

Usage

import useStateSet from '@tdukart/use-state-set';

function Foo() {
  const [greetings, addGreeting, removeGreeting] = useStateSet(new Set(['hello']));

  return (
    <div>
      <ul>
        {Array.from(greetings).map(greeting => (
          <li key={greeting}>{greeting}</li>
        ))}
      </ul>
      <button onClick={() => addGreeting('hi')}>Add "hi"</button>
      <button onClick={() => removeGreeting('hello')}>Remove "hello"</button>
    </div>
  );
}

Copyright/License

MIT licensed.

Copyright 2023 Todd Dukart.

Readme

Keywords

none

Package Sidebar

Install

npm i @tdukart/use-state-set

Weekly Downloads

2

Version

0.1.1

License

MIT

Unpacked Size

5.72 kB

Total Files

7

Last publish

Collaborators

  • tdukart