Skip to content

Commit 3aae602

Browse files
committedJun 14, 2020
feat: react integration
1 parent 6ca09dc commit 3aae602

File tree

4 files changed

+91
-4
lines changed

4 files changed

+91
-4
lines changed
 

‎docs/integrations/react.md

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
---
2+
id: react
3+
title: ⚛️ React
4+
---
5+
6+
Grid.js has native React wrapper which can be used to create Grid.js instance in a React app. Use [gridjs-react](https://github.com/grid-js/gridjs-react)
7+
package to integrate your React app with Grid.js.
8+
9+
## Install
10+
11+
```bash
12+
npm install --save gridjs-react
13+
```
14+
15+
Also, make sure you have Grid.js installed already as it's a peer dependency of `gridjs-react`:
16+
17+
```bash
18+
npm install --save gridjs
19+
```
20+
21+
## Usage
22+
23+
```js
24+
import { Grid } from 'gridjs-react';
25+
```
26+
27+
```jsx
28+
<Grid
29+
data={[
30+
['John', 'john@example.com'],
31+
['Mike', 'mike@gmail.com']
32+
]}
33+
columns={['Name', 'Email']}
34+
search={true}
35+
pagination={{
36+
enabled: true,
37+
limit: 1,
38+
}}
39+
/>
40+
```
41+
42+
Then you can pass all Grid.js configs to the `Grid` component. See [Grid.js Config](./config.md) for more details.
43+
44+
## Example
45+
46+
import { Grid } from 'gridjs-react';
47+
import CodeBlock from "@theme/CodeBlock"
48+
import { useEffect, useState } from "react";
49+
import * as faker from 'faker';
50+
51+
<CodeBlock children={
52+
`
53+
function MyComponent(props) {
54+
const row = () => [faker.name.findName(), faker.internet.email()];
55+
const [data, setData] = useState([row()]);
56+
const update = () => {
57+
setData(data.slice(0).concat([row()]));
58+
}
59+
60+
return (
61+
<div>
62+
<button onClick={update.bind(this)} className={"py-2 mb-4 px-4 border rounded-md text-white bg-blue-600"}>
63+
Add record
64+
</button>
65+
66+
<Grid
67+
data={data}
68+
columns={['Name', 'Email']}
69+
pagination={{
70+
limit: 5,
71+
}}
72+
/>
73+
</div>
74+
);
75+
}
76+
`
77+
} live={true} scope={{ Grid, CodeBlock, useEffect, useState, faker }} />
78+

‎package-lock.json

+5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"classnames": "^2.2.6",
1717
"faker": "^4.1.0",
1818
"gridjs": "file:../gridjs",
19+
"gridjs-react": "^1.5.0",
1920
"react": "^16.8.4",
2021
"react-dom": "^16.8.4"
2122
},

‎sidebars.js

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
module.exports = {
22
sidebar: {
3-
Introduction: ['index', 'philosophy', 'roadmap', 'community', 'license'],
4-
Usage: [
3+
"👋 Introduction": ['index', 'philosophy', 'roadmap', 'community', 'license'],
4+
"💁 Usage": [
55
'install',
66
'hello-world',
77
'config',
88
'server-side',
99
],
10-
Config: [
10+
"🛠 Config": [
1111
'config/data',
1212
'config/from',
1313
'config/columns',
@@ -19,7 +19,10 @@ module.exports = {
1919
'config/sort',
2020
'config/pagination',
2121
],
22-
Examples: [{
22+
"🔌 Integrations": [
23+
'integrations/react',
24+
],
25+
"🎮 Examples": [{
2326
type: 'category',
2427
label: 'Basic',
2528
items: [

0 commit comments

Comments
 (0)
Please sign in to comment.