storybook/docs/snippets/common/storybook-addons-api-useaddonstate.js.mdx

17 lines
504 B
Plaintext

```js
// /my-addon/register.js
import React from 'react';
import { useAddonState } from '@storybook/api';
export const Panel = () => {
const [state, setState] = useAddonState('my/addon-id', 'initial state');
return <button onClick={() => setState('a new value')}>the state = "{state}"</button>;
};
export const Tool = () => {
const [state, setState] = useAddonState('my/addon-id', 'initial state');
return <button onClick={() => setState('a new value')}>the state = "{state}"</button>;
};
```