mirror of
https://github.com/streamich/react-use.git
synced 2025-12-08 18:02:14 +00:00
* improve docs: useMap demo link * improve docs: useMap demo link (remove callback usage added) * Add remove action to useMap story
31 lines
584 B
Markdown
31 lines
584 B
Markdown
# `useMap`
|
|
|
|
React state hook that tracks a value of an object.
|
|
|
|
## Usage
|
|
|
|
```jsx
|
|
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>
|
|
);
|
|
};
|
|
```
|