File size: 845 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
import { storiesOf } from '@storybook/react';
import * as React from 'react';
import { useEvent, useList } from '../src';
import { CenterStory } from './util/CenterStory';
import ShowDocs from './util/ShowDocs';
const { useCallback } = React;
const Demo = () => {
const [list, { push, clear }] = useList();
const onKeyDown = useCallback(({ key }) => {
if (key === 'r') {
clear();
}
push(key);
}, []);
useEvent('keydown', onKeyDown);
return (
<CenterStory>
<p>
Press some keys on your keyboard, <code style={{ color: 'tomato' }}>r</code> key resets the
list
</p>
<pre>{JSON.stringify(list, null, 4)}</pre>
</CenterStory>
);
};
storiesOf('Sensors/useEvent', module)
.add('Docs', () => <ShowDocs md={require('../docs/useEvent.md')} />)
.add('Demo', () => <Demo />);
|