diff --git a/docs/snippets/react/button-story.with-hooks.js.mdx b/docs/snippets/react/button-story.with-hooks.js.mdx index 6c1f41e95d99..06c4cfec6cc6 100644 --- a/docs/snippets/react/button-story.with-hooks.js.mdx +++ b/docs/snippets/react/button-story.with-hooks.js.mdx @@ -1,5 +1,5 @@ ```js -// Button.stories.js|ts|jsx|tsx +// Button.stories.js|jsx import React, { useState } from 'react'; diff --git a/docs/snippets/react/button-story.with-hooks.ts-4-9.mdx b/docs/snippets/react/button-story.with-hooks.ts-4-9.mdx new file mode 100644 index 000000000000..486cc3b59644 --- /dev/null +++ b/docs/snippets/react/button-story.with-hooks.ts-4-9.mdx @@ -0,0 +1,43 @@ +```tsx +// Button.stories.ts|tsx + +import React, { useState } from 'react'; +import { Meta, StoryObj } from '@storybook/react'; + +import { Button } from './Button'; + +const meta = { + /* 👇 The title prop is optional. + * See https://storybook.js.org/docs/react/configure/overview#configure-story-loading + * to learn how to generate automatic titles + */ + title: 'Button', + component: Button, +} satisfies Meta; +export default meta; + +type Story = StoryObj; + +/* + * Example Button story with React Hooks. + * See note below related to this example. + */ +const ButtonWithHooks = () => { + // Sets the hooks for both the label and primary props + const [value, setValue] = useState('Secondary'); + const [isPrimary, setIsPrimary] = useState(false); + + // Sets a click handler to change the label's value + const handleOnChange = () => { + if (!isPrimary) { + setIsPrimary(true); + setValue('Primary'); + } + }; + return