Steve Kinney

Decorators

Decorators allow you to wrap the component in your story with another component. This is useful in a bunch of situations.

Additionally, @storybook/addons-themes uses decorators to apply themes to your stories.

Refactoring Our Text Area

Let’s imagine that we have a task list that relies on a Context API.

We can add the following to our story or to the meta:

const meta = {
  title: 'Components/TaskList',
  component: TaskList,
  decorators: [
    (Story) => (
      <TaskListProvider
        tasks={[
          { id: '1', title: 'Task 1', completed: false },
          { id: '2', title: 'Task 2', completed: true },
        ]}
      >
        <Story />
      </TaskListProvider>
    ),
  ],
} as Meta<typeof TaskList>;

Last modified on .