Skip to content

Commit 7b505b4

Browse files
authored
fix nextjs docs (#304)
1 parent 8ba4f4a commit 7b505b4

File tree

1 file changed

+6
-14
lines changed

1 file changed

+6
-14
lines changed

packages/website/docs/docs/nextjs.md

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,16 @@ path: /docs/nextjs
99

1010
BlockNote is a component that should only be rendered client-side (and not on the server). If you're using Next.js, you need to make sure that Next.js does not try to render BlockNote as a server-side component.
1111

12-
To do this, first see if you're using the modern [App router](https://nextjs.org/docs/app) or the classic [Pages router](https://nextjs.org/docs/pages).
13-
14-
(If the component you want to add BlockNote to is in an `app` directory, you're likely to be using the App router. If you're working in a `pages` directory, you're using the pages router).
15-
16-
## App router
17-
18-
Make sure to use BlockNote in a [Client Component](https://nextjs.org/docs/getting-started/react-essentials#client-components). You can do this by creating a separate file for your component, and starting that with `"use client";` [directive](https://react.dev/reference/react/use-client).
12+
Make sure to use BlockNote in a [Client Component](https://nextjs.org/docs/getting-started/react-essentials#client-components). You can do this by creating a separate file for your component (**make sure this sits outside of your `pages` or `app` directory**), and starting that with `"use client";` [directive](https://react.dev/reference/react/use-client):
1913

2014
```typescript
2115
"use client"; // this registers <Editor> as a Client Component
2216
import { BlockNoteEditor } from "@blocknote/core";
2317
import { BlockNoteView, useBlockNote } from "@blocknote/react";
2418
import "@blocknote/core/style.css";
2519

26-
// Our <Editor> component that we can now use
27-
export default Editor() {
20+
// Our <Editor> component we can reuse later
21+
export default function Editor() {
2822
// Creates a new editor instance.
2923
const editor: BlockNoteEditor | null = useBlockNote({});
3024

@@ -33,13 +27,11 @@ export default Editor() {
3327
}
3428
```
3529

36-
## Pages router
37-
38-
If you're using the classic Pages router (note that Next.js recommends upgrading to the App router) and are running into issues embedding BlockNote directly, you can use [Dynamic Imports](https://nextjs.org/docs/pages/building-your-application/optimizing/lazy-loading) to make sure BlockNote is only imported on the client-side.
30+
## Import as dynamic
3931

40-
First, create an isolated `<Editor>` component using the snipped above.
32+
Now, you can use [Dynamic Imports](https://nextjs.org/docs/pages/building-your-application/optimizing/lazy-loading) to make sure BlockNote is only imported on the client-side.
4133

42-
Then, you can import this using `next/dynamic` in your page:
34+
You can import the component we just created above using `next/dynamic` in your page:
4335

4436
```typescript
4537
import dynamic from "next/dynamic";

0 commit comments

Comments
 (0)