Skip to content

Commit 7109244

Browse files
authored
Merge pull request #10664 from marmelab/doc-update-nextjs-integration
[Doc] Update NextJS integration
2 parents a01dff4 + 9438b53 commit 7109244

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

docs/NextJs.md

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,19 @@ const AdminApp = () => (
7979
export default AdminApp;
8080
```
8181

82+
Then create a `src/components/Admin.tsx` file with the following:
83+
84+
```tsx
85+
"use client";
86+
import dynamic from "next/dynamic";
87+
88+
const AdminApp = dynamic(() => import("./AdminApp"), {
89+
ssr: false, // Required to avoid react-router related errors
90+
});
91+
92+
export default AdminApp;
93+
```
94+
8295
This is a minimal configuration to render CRUD pages for users, posts and comments. React-admin will guess the fields to display in the list and edition pages based on the API response.
8396

8497
## Exposing The Admin App Component
@@ -93,13 +106,11 @@ The file to modify depends on the router system you chose during setup:
93106
- Pages Router: `src/pages/index.tsx`.
94107

95108
```tsx
96-
import { NextPage } from "next";
97-
import dynamic from "next/dynamic";
98-
const AdminApp = dynamic(() => import("@/components/AdminApp"), { ssr: false });
99-
100-
const Home: NextPage = () => <AdminApp />;
109+
import Admin from "./components/Admin";
101110

102-
export default Home;
111+
export default function Page() {
112+
return <Admin />
113+
};
103114
```
104115

105116
Now, start the server with `yarn dev`, browse to `http://localhost:3000/`, and you should see the working admin:
@@ -120,15 +131,11 @@ This implies the creation of a new page in the Next.js app. Create a new file at
120131
No matter which system you choose, the file should contain the same code:
121132

122133
```tsx
123-
import { NextPage } from "next";
124-
import dynamic from "next/dynamic";
125-
const AdminApp = dynamic(() => import("@/components/AdminApp"), { ssr: false });
134+
import Admin from "../components/Admin";
126135

127-
const Admin: NextPage = () => {
128-
return <AdminApp />;
136+
export default function Page() {
137+
return <Admin />
129138
};
130-
131-
export default Admin;
132139
```
133140

134141
Now the admin renders at `http://localhost:3000/admin`. You can use the Next.js routing system to add more pages - for instance, a frontend app.

0 commit comments

Comments
 (0)