mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-08 09:31:47 +08:00
31 lines
754 B
Plaintext
31 lines
754 B
Plaintext
```tsx
|
|
// MyComponent.stories.ts|tsx
|
|
|
|
import type { Meta, StoryObj } from '@storybook/react';
|
|
|
|
import fetch from 'node-fetch';
|
|
|
|
import { TodoItem } from './TodoItem';
|
|
|
|
const meta: Meta<typeof TodoItem> = {
|
|
/* 👇 The title prop is optional.
|
|
* See https://storybook.js.org/docs/7.0/react/configure/overview#configure-story-loading
|
|
* to learn how to generate automatic titles
|
|
*/
|
|
title: 'Examples/Loader',
|
|
component: TodoItem,
|
|
render: (args, { loaded: { todo } }) => <TodoItem {...args} {...todo} />,
|
|
};
|
|
|
|
export default meta;
|
|
type Story = StoryObj<typeof TodoItem>;
|
|
|
|
export const Primary: Story = {
|
|
loaders: [
|
|
async () => ({
|
|
todo: await (await fetch('https://jsonplaceholder.typicode.com/todos/1')).json(),
|
|
}),
|
|
],
|
|
};
|
|
```
|