mirror of
https://github.com/streamich/react-use.git
synced 2026-02-01 14:37:31 +00:00
chore: clean tsconfig.json; feat: updated webpack config to export a function to achieve full-control mode, instead of deprecated Extend Mode;
26 lines
722 B
TypeScript
26 lines
722 B
TypeScript
import { storiesOf } from '@storybook/react';
|
|
import * as React from 'react';
|
|
import { useMap } from '../src';
|
|
import ShowDocs from './util/ShowDocs';
|
|
|
|
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>
|
|
);
|
|
};
|
|
|
|
storiesOf('State|useMap', module)
|
|
.add('Docs', () => <ShowDocs md={require('../docs/useMap.md')} />)
|
|
.add('Demo', () => <Demo />);
|