1.3.2 • Published 4 months ago

use-set-as-state v1.3.2

Weekly downloads
406
License
Apache-2.0
Repository
github
Last release
4 months ago

useSetAsState

A React Hook to use JavaScript's Set as React State, using an identical interface. Uses Immer under the hood.

This is a very lightweight package, it only depends on one other, extremely lightweight React hook (besides Immer itself).

Total package size is ~3KB including TypeScript types.

Docs

API Docs

Installation

npm i use-set-as-state immer

Usage

import { useSetAsState } from 'use-set-as-state';

const FunctionComponent = () => {
    const theSet = useSetAsState(new Set());

    const onClick = () => {
        theSet.add('checkboxChecked');
    };

    return <input type="checkbox" checked={theSet.has('checkboxChecked')}>;
};

Note: The add function returns the NEXT (Draft) state, even if the render has not occurred yet.

const onClick = () => {
    const draft = theSet.add('header');

    console.log(draft.has('header')); // true
};

Contributing

All contributions are welcome, please open an issue or pull request.

To use this repository: 1. npm i -g pnpm (if don't have pnpm installed) 2. pnpm i 3. npx projen (this will ensure everything is setup correctly, and you can run this command at any time) 4. Good to make your changes! 5. You can run npx projen build at any time to build the project.

1.3.2

4 months ago

1.3.1

4 months ago

1.2.2

4 months ago

1.3.0

4 months ago

1.2.1

4 months ago

1.2.0

4 months ago

1.1.1

4 months ago

1.1.3

4 months ago

1.1.2

4 months ago

1.1.0

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago