
If you’re wondering if you can use the JointJS for React library with the Next.js framework, the answer is a clear and resounding yes. In this post, you’ll learn everything you need to start using JointJS for React with Next.js, along with a crucial setup detail, and along the way you’ll pick up some tips for building your own production-grade diagramming applications.
First, we’ll set up a simple Next.js application. If you haven’t already, create a new Next.js project through your terminal:
npx create-next-app@latest jointjs-next-demo
cd jointjs-next-demoJointJS for React is available on NPM, so you can easily add it to your project:
npm install @joint/reactAfter installation, you’ll see @joint/react listed as a dependency in your package.json. At the time of writing, the latest version is 4.3.5.
Note that JointJS+ for React is available in a private NPM registry, so you’ll need an access token to use it:
npm install @joint/react-plusYou can find the guide on using the JointJS private NPM repository and setting up your access token in the docs: Using JointJS NPM Repository
Once you install JointJS for React, you’ll need to import the necessary components from the library along with the stylesheet into your application.
For this article, we’ll use the code from the JointJS for React Quickstart guide. We’ll go step by step, so first, we’ll import everything we need for this demo. Open your main app file, typically app/page.tsx, and replace the default import (import Image from "next/image";) with the following:
import { GraphProvider, Paper, HTMLBox } from '@joint/react';
import '@joint/react/styles.css';We’ll use GraphProvider, Paper, and HTMLBox components to render the JointJS diagram, and style.css for default styling.
Next, remove all default content from the return statement and add code from the quickstart guide:
export default function Home() {
// Cells used to create the initial graph at mount
const initialCells = [
{ id: '1', type: 'element', position: { x: 300, y: 140 }, data: { label: 'Hello' } },
{ id: '2', type: 'element', position: { x: 500, y: 200 }, data: { label: 'Next.js' } },
{
id: '1→2',
type: 'link',
source: { id: '1' },
target: { id: '2' },
style: { targetMarker: 'arrow' },
},
];
return (
<main>
<GraphProvider initialCells={initialCells}>
<Paper
renderElement={({ label }) => <HTMLBox>{label}</HTMLBox>}
style={{ height: 400 }}
/>
</GraphProvider>
</main>
);
}As we want the entire app to be a diagram, we’ll additionally tweak the style of the <Paper /> component: style={{ height: '100vh', width: '100%' }}. We’ll use Viewport Height units to ensure the diagram takes up 100% of the browser window's height. Note that height: 100%; will not work, as it requires a concrete height set on the parent element.
This is all you need for a simple JointJS for React app. But if you try to run it in the browser, you’ll get an error:

As it’s clearly outlined in the error message, JointJS for React is a client-side library, so you’ll need to add the 'use client'; directive to the top of the file because Next.js, by default, renders components on the server. The directive tells Next.js to render the component on the client side
When we add the 'use client'; directive, the full demo code will look like this:
'use client';
import { GraphProvider, Paper, HTMLBox } from '@joint/react';
import '@joint/react/styles.css';
export default function Home() {
const initialCells = [
{ id: '1', type: 'element', position: { x: 300, y: 140 }, data: { label: 'Hello' } },
{ id: '2', type: 'element', position: { x: 500, y: 200 }, data: { label: 'Next.js' } },
{
id: '1→2',
type: 'link',
source: { id: '1' },
target: { id: '2' },
style: { targetMarker: 'arrow' },
},
];
return (
<main>
<GraphProvider initialCells={initialCells}>
<Paper
renderElement={({ label }) => <HTMLBox>{label}</HTMLBox>}
style={{ height: '100vh', width: '100%' }}
/>
</GraphProvider>
</main>
);
}
And this is what our interactive diagramming demo app will look like:

Now that you know how to make JointJS for React work with Next.js, you can continue following our Quickstart Guide to become familiar with all the key concepts, or try one of the following:
Getting JointJS for React running in your Next.js application is straightforward. The only thing you really need is the use client directive at the top of components where you set up your diagrams. For more details and advanced topics, check out our JointJS for React Quickstart guide and documentation.
Happy diagramming!