-
SummaryHi everyone. Please tell me how to update Additional informationI use Vue 3, Vite, Storybook 8.3.4 with default configs. I want the There are examples of using
Error code piece: import { useArgs } from '@storybook/manager-api';
import Modal from './Modal.vue';
const meta = {
title: 'Example/Modal',
component: Modal,
render: args => ({
components: {
Modal,
},
setup() {
const [_, updateArgs] = useArgs(); // error occurs here
const clickHandler = () => {
updateArgs({ show: true });
};
const closeHandler = () => {
updateArgs({ show: false });
};
return { args, clickHandler, closeHandler };
},
template: `
<button @click="clickHandler">Open modal</button>
<Modal :=args @close="closeHandler">
<template #default>
{{ args.default}}
</template>
</Modal>
`,
}),
... Thank you in advance for your help. Create a reproductionLink to code. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
Hi, This link helped me find a solution: The workaround was to make it available through a decorator. I was using Storybook 8.4.7. In import { useArgs } from '@storybook/client-api'
export const decorators = [
(story, context) => {
const [_, updateArgs] = useArgs()
return story({ ...context, updateArgs })
},
] Then in your render function or Template of your Story you can access the export const metaVue: MetaVue<typeof Table> = {
// -----------------👇 you get it from here
render: (args, {updateArgs}) => ({
components: { Table },
setup() {
// 👉 and here you can call updateArgs
}
})
} |
Beta Was this translation helpful? Give feedback.
-
Thanks for your Help! |
Beta Was this translation helpful? Give feedback.
-
Here is the final result. preview.ts: import { useArgs } from '@storybook/preview-api';
const preview: Preview = {
...
decorators: [
(story, context) => {
const [_, updateArgs] = useArgs();
return story({ ...context, updateArgs });
},
],
}; Modal.stories.ts: const meta = {
title: 'Example/Modal'
component: Modal,
render: (args, { updateArgs }) => ({
components: {
Modal,
},
setup() {
const clickHandler = () => {
updateArgs({ ...args, show: true });
};
const closeHandler = () => {
updateArgs({ ...args, show: false });
};
return { args, clickHandler, closeHandler };
},
template: `
<button @click="clickHandler">Modal open</button>
<Modal :=args @close="closeHandler">
<template #default>
{{ args.default}}
</template>
</Modal>
`,
}),
...
} satisfies Meta<typeof Modal>; |
Beta Was this translation helpful? Give feedback.
Hi,
I was not able to use
useArgs
, I got your same error.This link helped me find a solution:
https://craigbaldwin.com/blog/updating-args-storybook-vue/
The workaround was to make it available through a decorator. I was using Storybook 8.4.7.
In
preview.ts
you add a decorator:Then in your render function or Template of your Story you can access the
updateArgs
function to update the args of the Story so they are reflected in the controls panel of Storybook: