The Storybook Links addon can be used to create links between stories in Storybook.
This addon works with Storybook for: React and React Native.
You can use this addon without installing it.
import { storiesOf } from '@storybook/react'
import { linkTo } from '@storybook/addon-links'
storiesOf('Button', module)
.add('First', () => (
<button onClick={linkTo('Button', 'Second')}>Go to "Second"</button>
))
.add('Second', () => (
<button onClick={linkTo('Button', 'First')}>Go to "First"</button>
));
Have a look at the linkTo function:
import { linkTo } from '@storybook/addon-links'
linkTo('Toggle', 'off')
With that, you can link an event in a component to any story in the Storybook.
- First parameter is the the story kind name (what you named with
storiesOf
). - Second parameter is the story name (what you named with
.add
).
You can also pass a function instead for any of above parameter. That function accepts arguments emitted by the event and it should return a string.
Have a look at PR86 for more information.