-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add stories for Unmount and Mount
- Loading branch information
Showing
2 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 />); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 />); |