Next.js
Configure Fumadocs Story on Next.js.
Installation
npm i @fumadocs/storyAdd the Tailwind CSS preset.
@import '@fumadocs/story/css/preset.css';Create a Story
Create a story factory to store your global settings:
import { createFileSystemCache, defineStoryFactory } from '@fumadocs/story';
export const { defineStory } = defineStoryFactory({
// for Vercel, this is required: choose a directory for cache.
cache:
process.env.NODE_ENV === 'production'
? createFileSystemCache('.next/fumadocs-story')
: undefined,
tsc: {
// we use tsc to generate controls from types
// you can pass TypeScript options here
},
});Now create your first story:
import { defineStory } from '@/lib/story';
import { MyComponent } from './my-component';
export const story = defineStory(import.meta.url, {
Component: MyComponent,
args: {
// default props (recommended)
initial: {},
},
});- The story must be defined in a server component.
- The story must be exported as
story, or thenameoption must be set to match the export name. - Fill the
Componentoption with your component, the passed component must be a client component.
Now you can render the story like:
import { story } from '@/components/my-component.story';
## Overview
Preview for component:
<story.WithControl />How is this guide?
Last updated on
