storybook/docs/snippets/angular/loader-story.ts.mdx
2021-11-03 23:31:14 +00:00

42 lines
877 B
Plaintext

```ts
// TodoItem.stories.ts
mport { Meta, moduleMetadata, Story } from '@storybook/angular';
import fetch from 'node-fetch';
import { CommonModule } from '@angular/common';
import { TodoItem } from './TodoItem';
export default {
/* 👇 The title prop is optional.
* See https://storybook.js.org/docs/angular/configure/overview#configure-story-loading
* to learn how to generate automatic titles
*/
title: 'Examples/Loader',
component: TodoItem,
decorators: [
moduleMetadata({
declarations: [TodoItem],
imports: [CommonModule],
}),
],
title: 'Examples/Loader',
} as Meta;
export const Primary = (args, { loaded: { todo } }) => {
return {
props: {
args,
todo,
},
};
};
Primary.loaders = [
async () => ({
todo: await (await fetch('https://jsonplaceholder.typicode.com/todos/1')).json(),
}),
];
```