react-use/docs/useMap.md
Arty c520797fd5 docs: useMap demo link + improved docs (#650)
* improve docs: useMap demo link

* improve docs: useMap demo link (remove callback usage added)

* Add remove action to useMap story
2019-10-07 16:02:45 +11:00

584 B

useMap

React state hook that tracks a value of an object.

Usage

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>
  );
};