Skip to content

Latest commit

 

History

History
35 lines (30 loc) · 904 Bytes

useMap.md

File metadata and controls

35 lines (30 loc) · 904 Bytes

useMap

Vue state hook that tracks a value of an object.

Usage

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

const Demo = {
    setup() {
        const [map, {set, setAll, remove, reset}] = useMap({
            hello: 'there',
        });

        return () => (
            <div>
                <button onClick={() => set(String(Date.now()), new Date().toJSON())}>
                    Add
                </button>
                <button onClick={() => reset()}>
                    Reset
                </button>
                <button onClick={() => setAll({hello: 'new', data: 'data'})}>
                    Set new data
                </button>
                <button onClick={() => remove('hello')} disabled={!map.hello}>
                    Remove 'hello'
                </button>
                <pre>{JSON.stringify(map, null, 2)}</pre>
            </div>
        );
    }
};