Skip to content

Commit

Permalink
Merge pull request #8990 from marmelab/useclient
Browse files Browse the repository at this point in the history
Fix `<Admin>` fails when used in Next.js server components
  • Loading branch information
djhi committed Jun 9, 2023
2 parents fa5501f + e4dbf82 commit 3cb4303
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
3 changes: 1 addition & 2 deletions docs/NextJs.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,6 @@ Next, replace the `app/pages.tsx` file with the following code, which initialize

```jsx
// in app/pages.tsx
"use client";
import { Admin, Resource, ListGuesser, EditGuesser } from "react-admin";
import jsonServerProvider from "ra-data-json-server";

Expand All @@ -246,6 +245,6 @@ Now, start the server with `yarn dev`, browse to `http://localhost:3000/`, and y

React-admin renders a CRUD for users, posts and comments, guessing the data structure from the API response.

**Tip**: Why the `"use client"` directive? React-admin is designed as a Single-Page Application, rendered on the client-side. It comes with various client-side only libraries (emotion, material-ui, react-query) leveraging the React Context API, and cannot be rendered using React Server components.
**Tip**: The `<Admin>` component uses the `"use client"` directive, because React-admin is designed as a Single-Page Application, rendered on the client-side. It comes with various client-side only libraries (emotion, material-ui, react-query) leveraging the React Context API, and cannot be rendered using React Server components.

Starting from there, you can [Add an API](#adding-an-api) as described in the previous section, and/or add features to the Next.js app, as explained in the [Getting started tutorial](./GettingStarted.md)
1 change: 1 addition & 0 deletions packages/react-admin/src/Admin.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use client';
import * as React from 'react';
import { ComponentType } from 'react';
import { CoreAdminProps, localStorageStore } from 'ra-core';
Expand Down

0 comments on commit 3cb4303

Please sign in to comment.