useMap

React 状态钩子,用于追踪对象型值。

用法

  1. import {useMap} from 'react-use';
  2. const Demo = () => {
  3. const [map, {set, reset}] = useMap({
  4. hello: 'there',
  5. });
  6. return (
  7. <div>
  8. <pre>{JSON.stringify(map, null, 2)}</pre>
  9. <button onClick={() => set(String(Date.now()), (new Date()).toJSON())}>Add</button>
  10. <button onClick={() => reset()}>Reset</button>
  11. </div>
  12. );
  13. };