From 67c51e3f06ab25784599e54990dd646c1a9c9a39 Mon Sep 17 00:00:00 2001 From: tsengyushiang Date: Tue, 6 Aug 2024 10:20:07 +0800 Subject: [PATCH] Update storybook.md --- frontend/storybook.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/frontend/storybook.md b/frontend/storybook.md index 42055bf..2f14bb1 100644 --- a/frontend/storybook.md +++ b/frontend/storybook.md @@ -108,6 +108,31 @@ const meta = { ], } ``` +### Arguments Mutation + +- [reference](https://storybook.js.org/docs/writing-stories/args#setting-args-from-within-a-story) + +```javascript +import { useArgs } from "@storybook/preview-api"; + +export const Page: Story = { + args: { + currentPage: 5, + onChange: fn(), + }, + render: (args) => { + const [_, updateArgs] = useArgs(); + + function onChange(_: any, page: number) { + args.onChange(_, page); + updateArgs({ currentPage: page }); + } + + return ; + }, +}; +``` + ## Setup Mock Service Worker ### Installation