|
Download react-use/docs/useMap.md from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 699 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/react-use/docs/useMap.md
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/react-use/docs/useMap.md
-
curl -L -o useMap.md https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/react-use/docs/useMap.md
699 Bytes
useMap
React state hook that tracks a value of an object.
Usage
import {useMap} from 'react-use';
const Demo = () => {
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>
);
};