Skip to content

Commit d45f3b0

Browse files
authored
Merge pull request #8054 from marmelab/doc-vite
[Doc] Add Vite integration doc
2 parents 4302137 + 1ae6721 commit d45f3b0

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

docs/Vite.md

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
---
2+
layout: default
3+
title: "Vite Integration"
4+
---
5+
6+
# Vite Integration
7+
8+
[Vite](https://vitejs.dev/) is a JavaScript bundler which improves speed of dev server and production build compared to Webpack.
9+
10+
## Setting Up React App with Vite
11+
12+
Create a new Vite project with React template using the command line:
13+
14+
```sh
15+
yarn create vite my-admin --template react
16+
```
17+
18+
We recommend using the TypeScript template:
19+
20+
```sh
21+
yarn create vite my-admin --template react-ts
22+
```
23+
24+
## Setting Up React-Admin
25+
26+
Add the `react-admin` package, as well as a data provider package. In this example, we'll use `ra-data-json-server` to connect to a test API provided by [JSONPlaceholder](https://jsonplaceholder.typicode.com).
27+
28+
```sh
29+
cd my-admin
30+
yarn add react-admin ra-data-json-server
31+
```
32+
33+
Next, create the admin app component in `src/admin/index.tsx`:
34+
35+
```jsx
36+
// in src/admin/index.tsx
37+
import { Admin, Resource, ListGuesser } from "react-admin";
38+
import jsonServerProvider from "ra-data-json-server";
39+
40+
const dataProvider = jsonServerProvider("https://jsonplaceholder.typicode.com");
41+
42+
const App = () => (
43+
<Admin dataProvider={dataProvider}>
44+
<Resource name="posts" list={ListGuesser} />
45+
<Resource name="comments" list={ListGuesser} />
46+
</Admin>
47+
);
48+
49+
export default App;
50+
```
51+
52+
This is a minimal admin for 2 resources. React-admin should be able to render a list of posts and a list of comments, guessing the data structure from the API response.
53+
54+
Next, replace the `App.tsx` component with the following:
55+
56+
```jsx
57+
import MyAdmin from "./admin";
58+
59+
const App = () => <MyAdmin />;
60+
61+
export default App;
62+
```
63+
64+
Now, start the server with `yarn dev`, browse to `http://localhost:5173/`, and you should see the working admin:
65+
66+
![Working Page](./img/nextjs-react-admin.webp)
67+
68+
Your app is now up and running, you can start tweaking it.

docs/navigation.html

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<ul><div>Getting Started</div>
55
<li {% if page.path == 'Tutorial.md' %} class="active" {% endif %}><a class="nav-link" href="./Tutorial.html">Tutorial</a></li>
66
<li {% if page.path == 'CreateReactApp.md' %} class="active" {% endif %}><a class="nav-link" href="./CreateReactApp.html">Create React App</a></li>
7+
<li {% if page.path == 'Vite.md' %} class="active" {% endif %}><a class="nav-link" href="./Vite.html">Vite</a></li>
78
<li {% if page.path == 'NextJs.md' %} class="active" {% endif %}><a class="nav-link" href="./NextJs.html">Next.js</a></li>
89
<li {% if page.path == 'Remix.md' %} class="active" {% endif %}><a class="nav-link" href="./Remix.html">Remix</a></li>
910
</ul>

0 commit comments

Comments
 (0)