storybook/docs/snippets/common/storybook-addons-api-useparameter.js.mdx
2023-04-04 20:09:52 +01:00

25 lines
668 B
Plaintext

```js
// my-addon/manager.js|ts
import React from 'react';
import { AddonPanel } from '@storybook/components';
import { useParameter } from '@storybook/manager-api';
export const Panel = () => {
// Connects to Storybook's API and retrieves the value of the custom parameter for the current story
const value = useParameter('custom-parameter', 'initial value');
return (
<AddonPanel key="custom-panel" active="true">
{value === 'initial value' ? (
<h2>The story doesn't contain custom parameters. Defaulting to the initial value.</h2>
) : (
<h2>You've set {value} as the parameter.</h2>
)}
</AddonPanel>
);
};
```