react-use/stories/useDeepCompareEffect.story.tsx
Anton Zinovyev 2832b7a37e
chore: move all stories from src directory. (#715)
chore: clean tsconfig.json;

feat: updated webpack config to export a function to achieve full-control mode, instead of deprecated Extend Mode;
2019-12-09 23:36:40 +03:00

34 lines
854 B
TypeScript

import { storiesOf } from '@storybook/react';
import * as React from 'react';
import { useCounter, useDeepCompareEffect } from '../src';
import ShowDocs from './util/ShowDocs';
const Demo = () => {
const [countNormal, { inc: incNormal }] = useCounter(0);
const [countDeep, { inc: incDeep }] = useCounter(0);
const options = { max: 500 };
React.useEffect(() => {
if (countNormal < options.max) {
incNormal();
}
}, [options]);
useDeepCompareEffect(() => {
if (countNormal < options.max) {
incDeep();
}
}, [options]);
return (
<div>
<p>useEffect: {countNormal}</p>
<p>useDeepCompareEffect: {countDeep}</p>
</div>
);
};
storiesOf('Lifecycle|useDeepCompareEffect', module)
.add('Docs', () => <ShowDocs md={require('../docs/useDeepCompareEffect.md')} />)
.add('Demo', () => <Demo />);