Skip to content

Storybook Testing (React)

LiveStore works seamlessly with Storybook for React component development and testing.

Note: This guide focuses on React. For other frameworks, adapt patterns accordingly.

First, install Storybook in your React project.

Create a decorator that wraps stories with a fresh LiveStore instance and use the TodoMVC schema for realistic examples.

src/TodoInput.stories.tsx
import type { Meta, StoryObj } from '@storybook/react'
import { TodoInput } from './TodoInput'
import { createLiveStoreDecorator } from './decorator'
import { events } from './schema'
const meta: Meta<typeof TodoInput> = {
title: 'TodoMVC/TodoInput',
component: TodoInput,
}
export default meta
type Story = StoryObj<typeof TodoInput>
export const Default: Story = {}
export const WithInitialText: Story = {
decorators: [
createLiveStoreDecorator([
events.uiStateSet({ newTodoText: 'Buy groceries' })
])
],
}