#server components in storybook v7 Next.js Beta

2 messages · Page 1 of 1 (latest)

distant flax
#

My understanding is that server components are not officially supported in the Next.js storybook beta for v7, but that there was a workaround for this. However, I'm a bit confused how that applies directly to stories.

I have a story that normally looks like this, where Component is a server component that is async:

import React from "react";
import { StoryFn, Meta } from "@storybook/react";
import Component from ".";

// type error here
export default {
  title: "Component",
  component: Component,
} as Meta<typeof Component>;

const Template: StoryFn<typeof Component> = (args) => (
  // type error here
  <Component {...args} />
);

export const Default = Template.bind({});

Default.args = {
  // args go here
};

Essentially not compatible (obviously) because a Promise<Element> is not compatible with the typical ReactElement. Is there a current workaround for this?

half mural
#

Extract the UI part of your server component into a separate component and use this instead in Storybook. I think that's the way to go.