import type { Meta, StoryObj } from '@storybook/react-vite' import { useState } from 'react' import { Button } from './Button' import { ErrorBoundary } from './ErrorBoundary' /** * A part of the page that crashes shows this in its place, and the rest of the * page keeps working. Try again draws the part again. */ const meta = { title: 'Feedback/ErrorBoundary', component: ErrorBoundary, parameters: { layout: 'fullscreen' }, args: { label: 'panel', children: null }, argTypes: { children: { control: false }, frame: { control: false } }, } satisfies Meta export default meta type Story = StoryObj function Broken(): never { throw new Error('This part could not draw itself') } /** A panel that crashed, beside one that did not. */ export const InAPanel: Story = { args: { label: 'panel' }, render: (args) => (
The rest of the page keeps working.
), } /** Try again draws the part again: here the part is mended first, so it comes back. */ export const TryAgain: Story = { parameters: { controls: { disable: true } }, render: function Mend() { const [mended, setMended] = useState(false) function Part() { if (!mended) throw new Error('This part could not draw itself') return

The part is back.

} return (
) }, }