import React, { ReactNode } from "react";
import { Meta } from "@storybook/react";
import { DataLoader } from "../components/data-loader/DataLoader";
export default {
title: "Data Loader",
component: DataLoader,
} as Meta;
type Post = {
title: string;
body: string;
};
export const loadPosts = () => {
const PostLoader = (props: { url: string; children: ReactNode }) => {
const loader = async () => {
const wait = (ms: number, value: Post) =>
new Promise((resolve) => setTimeout(resolve, ms, value));
return await fetch(props.url)
.then((res) => res.json())
.then((value) => wait(3000, value));
};
return {props.children};
};
return (
{(posts: Post[]) => (
Name |
Description |
{posts.map((post, i) => (
{post.title} |
{post.body} |
))}
)}
);
};