React state hook that tracks a value of an object.
import {useMap} from 'react-use';
const Demo = () => {
const [map, {set, 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={() => remove('hello')} disabled={!map.hello}>
Remove 'hello'
</button>
<pre>{JSON.stringify(map, null, 2)}</pre>
</div>
);
};