Skip to content

Latest commit

 

History

History
27 lines (22 loc) · 821 Bytes

useSet.md

File metadata and controls

27 lines (22 loc) · 821 Bytes

useSet

Vue state hook that tracks a Set.

Usage

import {useSet} from 'vue-next-use';

const Demo = {
    setup(){
        const [set, { add, has, remove, toggle, 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>
                <button onClick={() => toggle('hello')}>Toggle hello</button>
                <pre>{JSON.stringify(Array.from(set), null, 2)}</pre>
            </div>
        );
    }
};