Skip to content

Commit

Permalink
feat: add stories for Unmount and Mount
Browse files Browse the repository at this point in the history
  • Loading branch information
yeojz committed Apr 7, 2019
1 parent fc82c35 commit 8427710
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
35 changes: 35 additions & 0 deletions stories/UseMount.story.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/* eslint-disable */
import * as React from 'react';
import { storiesOf } from '@storybook/react';
import { action } from '@storybook/addon-actions';
import withState from './withState';
import UseMount from '../src/UseMount';

const { Fragment } = React;

function Example(props) {
const { mounted, setMounted } = props;

return (
<div>
{!mounted && (
<Fragment>
<button onClick={() => setMounted(true)}>Mount the component.</button>
<p>Upon mounting, an action will fire.</p>
</Fragment>
)}

{mounted && (
<UseMount
fn={() => {
action('UseMount')('mounted');
}}
/>
)}
</div>
);
}

const Demo = withState('mounted', 'setMounted', false)(Example);

storiesOf('2. Additional|UseMount', module).add('Demo', () => <Demo />);
35 changes: 35 additions & 0 deletions stories/UseUnmount.story.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/* eslint-disable */
import * as React from 'react';
import { storiesOf } from '@storybook/react';
import { action } from '@storybook/addon-actions';
import withState from './withState';
import UseUnmount from '../src/UseUnmount';

const { Fragment } = React;

function Example(props) {
const { mounted, setMounted } = props;

return (
<div>
{mounted && (
<Fragment>
<button onClick={() => setMounted(false)}>Unmount the component.</button>
<p>Upon mounting, an action will fire.</p>
</Fragment>
)}

{mounted && (
<UseUnmount
fn={() => {
action('UseUnmount')('unmounted');
}}
/>
)}
</div>
);
}

const Demo = withState('mounted', 'setMounted', true)(Example);

storiesOf('2. Additional|UseUnmount', module).add('Demo', () => <Demo />);

0 comments on commit 8427710

Please sign in to comment.