Hey there everyone, I'm pretty new to storybook and tried to look for answer on docs, on the web and even youtube but can"t find the exact answer.
I want to put data on my stories that comes from an API.
Following the doc I tried to get a loader and get the result in a render function as this code :
import type { Meta, StoryObj } from "@storybook/react";
import DesignerCard from "./DesignerCard";
import { findDesignerBySlug } from "@/utils/lib/directus/designer";
import { IDesigner } from "@/utils/interfaces/IDesigner";
const meta: Meta<typeof DesignerCard> = {
title: "Design System/Molecules/DesignerCard",
component: DesignerCard,
parameters: {
layout: "centered",
},
tags: ["autodocs"],
};
export default meta;
type Story = StoryObj<typeof DesignerCard>;
export const Primary: StoryObj<{ designer: IDesigner }> = {
loaders: [
async () => ({
designer: await findDesignerBySlug("nantes"),
}),
],
render: (args, { loaded: designer }) => <DesignerCard {...args} designer={designer} />,
};
try even a global loader in the preview file :
import type { Preview } from "@storybook/react";
import "../app/reset.scss";
import "../app/global.scss";
import "../app/swiper.scss";
import "../app/leaflet.scss";
import "../app/directus.scss";
import { findDesignerBySlug } from "../utils/lib/directus/designer";
const preview: Preview = {
loaders: [
async () => ({
designer: await await findDesignerBySlug("nantes"),
}),
],
parameters: {
actions: { argTypesRegex: "^on[A-Z].*" },
controls: {
matchers: {
color: /(background|color)$/i,
date: /Date$/,
},
},
},
};
export default preview;```
So my question is : What am I doing wrong? 😅 Thank you for your time, I appreciate it.