
Security News
Scaling Socket from Zero to 10,000+ Organizations
Socket CEO Feross Aboukhadijeh shares lessons from scaling a developer security startup to 10,000+ organizations in this founder interview.
@storybook/addon-links
Advanced tools
Storybook Links: Link stories together to build demos and prototypes with your UI components
The Storybook Links addon can be used to create links that navigate between stories in Storybook.
Install this addon by adding the @storybook/addon-links dependency:
yarn add -D @storybook/addon-links
within .storybook/main.js:
export default {
addons: ['@storybook/addon-links'],
};
Then you can import linkTo in your stories and use like this:
import { linkTo } from '@storybook/addon-links';
export default {
title: 'Button',
};
export const first = () => <button onClick={linkTo('Button', 'second')}>Go to "Second"</button>;
export const 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');
linkTo(
() => 'Toggle',
() => 'off'
);
linkTo('Toggle'); // Links to the first story in the 'Toggle' kind
With that, you can link an event in a component to any story in the Storybook.
title).exported name).
If the second parameter is omitted, the link will point to the first story in the given kind.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:
import { linkTo } from '@storybook/addon-links';
import LinkTo from '@storybook/addon-links/react';
export default {
title: 'Select',
};
export const index = () => (
<select value="Index" onChange={linkTo('Select', (e) => e.currentTarget.value)}>
<option>index</option>
<option>first</option>
<option>second</option>
<option>third</option>
</select>
);
export const first = () => <LinkTo story="index">Go back</LinkTo>;
export const second = () => <LinkTo story="index">Go back</LinkTo>;
export const third = () => <LinkTo story="index">Go back</LinkTo>;
If you want to get an URL for a particular story, you may use hrefTo function. It returns a promise, which resolves to string containing a relative URL:
import { hrefTo } from '@storybook/addon-links';
import { action } from 'storybook/actions';
export default {
title: 'Href',
};
export const log = () => {
hrefTo('Href', 'log').then(action('URL of this story'));
return <span>See action logger</span>;
};
withLinks decorator enables a declarative way of defining story links, using data attributes.
Here is an example in React, but it works with any framework:
import { withLinks } from '@storybook/addon-links';
export default {
title: 'Button',
decorators: [withLinks],
};
export const first = () => (
<button data-sb-kind="OtherKind" data-sb-story="otherStory">
Go to "OtherStory"
</button>
);
One possible way of using hrefTo is to create a component that uses native a element, but prevents page reloads on plain left click, so that one can still use default browser methods to open link in new tab.
A React implementation of such a component can be imported from @storybook/addon-links package:
import LinkTo from '@storybook/addon-links/react';
export default {
title: 'Link',
};
export const first = () => <LinkTo story="second">Go to Second</LinkTo>;
export const second = () => <LinkTo story="first">Go to First</LinkTo>;
It accepts all the props the a element does, plus story and kind. It the kind prop is omitted, the current kind will be preserved.
<LinkTo
kind="Toggle"
story="off"
target="_blank"
title="link to second story"
style={{ color: '#1474f3' }}
>
Go to Second
</LinkTo>
To implement such a component for another framework, you need to add special handling for click event on native a element. See RoutedLink sources for reference.
Learn more about Storybook at storybook.js.org.
The @storybook/addon-actions package can be used to log actions performed on UI components within Storybook. While it doesn't provide direct linking between stories like @storybook/addon-links, it is often used in conjunction with links to provide a more interactive storytelling experience.
The @storybook/addon-knobs package allows you to add dynamic variables to your stories in Storybook. Similar to @storybook/addon-links, it enhances the interactivity of stories by allowing users to manipulate props in real-time. However, it does not provide functionality for linking between stories.
FAQs
Storybook Links: Link stories together to build demos and prototypes with your UI components
The npm package @storybook/addon-links receives a total of 4,819,002 weekly downloads. As such, @storybook/addon-links popularity was classified as popular.
We found that @storybook/addon-links demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 12 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Socket CEO Feross Aboukhadijeh shares lessons from scaling a developer security startup to 10,000+ organizations in this founder interview.

Research
Socket Threat Research maps a rare inside look at OtterCookie’s npm-Vercel-GitHub chain, adding 197 malicious packages and evidence of North Korean operators.

Research
Socket researchers identified a malicious Chrome extension that manipulates Raydium swaps to inject an undisclosed SOL transfer, quietly routing fees to an attacker wallet.