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;
34 lines
837 B
TypeScript
34 lines
837 B
TypeScript
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 />);
|