Skip to content

Integrate Next.js with Storyblok

Use Storyblok to manage the content of your Next.js project. Follow this guide to learn how to fetch content, register components, set up previews, configure a catch-all route, and build a content model.

The fastest way to get started is using Storyblok’s Core Blueprint or CLI wizard:

Use Storyblok’s Core Blueprint to launch a Next.js project, complete with a space, GitHub repository, and deployment environment.

Log in to Storyblok, select + Add Space → Start from Blueprint, and follow the steps.

Alternatively, set up the project from scratch and configure your frontend code.

This guide has been tested with the following package versions:
  • next@16.4.6
  • react@19.3.0
  • react-dom@19.3.0
  • @storyblok/react@8.0.0
  • @storyblok/api-client@0.14.0
  • Node.js v24.22.1
  1. Create a new space

    Log in to Storyblok, select + Add Space → New Space, and follow the steps.

  2. Create a Next.js project

    Create a new Next.js project with JavaScript and a src directory. In the terminal, run:

    Terminal window
    npx create-next-app@latest my-app --js --src-dir --no-cache-components

    The pages in this guide fetch data while they render, so the project needs Cache Components turned off. For other options, refer to the official Next.js installation guide.

  3. Install @storyblok/react and @storyblok/api-client

    In the terminal, cd into the project, and install dependencies.

    Terminal window
    npm install @storyblok/react @storyblok/api-client

Next, in the root of your project, create a .env file with the access token from your space.

.env
STORYBLOK_DELIVERY_API_TOKEN=<YOUR-ACCESS-TOKEN>

In src/lib, create a file named storyblok.js and initialize the Storyblok API client and React SDK.

src/lib/storyblok.js
import { createApiClient } from "@storyblok/api-client";
import { defineStoryblokBlocks } from "@storyblok/react";
export const apiClient = createApiClient({
accessToken: process.env.STORYBLOK_DELIVERY_API_TOKEN,
region: "eu", // Choose the correct region of your space.
});
export const { StoryblokBlock } = defineStoryblokBlocks(() => ({
components: {},
}));

Set the region that matches the server location of your Storyblok space.

This guide uses @storyblok/api-client to fetch data. Alternatively, use storyblok-js-client, or the native fetch API.

Replace the code in src/app/page.js with the following.

src/app/page.js
import { notFound } from "next/navigation";
import { apiClient, StoryblokBlock } from "@/lib/storyblok";
import { Suspense } from "react";
export default async function Home() {
const storyPromise = apiClient.stories.get("home", { query: { version: "draft" } });
return (
<Suspense fallback={<main>Loading...</main>}>
<PageContent storyPromise={storyPromise} />
</Suspense>
);
}
async function PageContent({ storyPromise }) {
const { data, error } = await storyPromise;
if (error?.response.status === 404) {
notFound();
}
if (error) {
throw error;
}
return <StoryblokBlock block={data.story.content} />;
}

This page fetches the home story of your Storyblok space. The PageContent component awaits the request and streams in once it resolves, while Suspense shows the fallback in the meantime.

The API client returns a missing story as a 404 error. PageContent calls notFound() for it and throws every other error, such as an invalid access token, so it doesn’t show as a missing page.

StoryblokBlock renders content type and nestable blocks with the component registered under the block’s technical name. The home story uses the page content type, so StoryblokBlock looks for a page component.

Create a src/components/Page.jsx component to render all stories of the page content type, such as the home story.

src/components/Page.jsx
import { StoryblokBlock } from "@/lib/storyblok";
export default function Page({ block }) {
return (
<main>
{block.body?.map((nestedBlock) => (
<StoryblokBlock block={nestedBlock} key={nestedBlock._uid} />
))}
</main>
);
}

Use StoryblokBlock to iterate through the body field and render the blocks in it.

Stories can have a body field that contains an array of custom type blocks, such as Feature, Teaser, and Grid.

Create the code for these components as follows.

src/components/Feature.jsx
export default function Feature({ block }) {
return (
<div className="feature">
<span>{block.name}</span>
</div>
);
}
src/components/Teaser.jsx
export default function Teaser({ block }) {
return (
<div className="teaser">
<h2>{block.headline}</h2>
</div>
);
}
src/components/Grid.jsx
import { StoryblokBlock } from "@/lib/storyblok";
export default function Grid({ block }) {
return (
<div className="grid">
{block.columns?.map((nestedBlock) => (
<StoryblokBlock block={nestedBlock} key={nestedBlock._uid} />
))}
</div>
);
}

Similar to Page.jsx, Grid.jsx iterates over the columns block field.

Register the components in storyblok.js. The key must match the block’s technical name.

src/lib/storyblok.js
import { createApiClient } from "@storyblok/api-client";
import { defineStoryblokBlocks } from "@storyblok/react";
import Page from "@/components/Page";
import Teaser from "@/components/Teaser";
import Feature from "@/components/Feature";
import Grid from "@/components/Grid";
export const apiClient = createApiClient({
accessToken: process.env.STORYBLOK_DELIVERY_API_TOKEN,
region: "eu", // Choose the correct region of your space.
});
export const { StoryblokBlock } = defineStoryblokBlocks(() => ({
components: {},
components: {
page: Page,
teaser: Teaser,
feature: Feature,
grid: Grid,
},
}));

Run the server and visit the site in your browser.

Terminal window
npm run dev

Was this page helpful?

What went wrong?

This site uses reCAPTCHA and Google's Privacy Policy (opens in a new window).Terms of Service (opens in a new window) apply.