Skip to content

Commit b7b4fe4

Browse files
committed
docs: Update README for v2 (#157)
1 parent 36cc088 commit b7b4fe4

File tree

2 files changed

+46
-54
lines changed

2 files changed

+46
-54
lines changed

README.md

Lines changed: 46 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
<div align="center">
2-
<img alt="Logo" src="static/react-editor-js.png" width="400px">
2+
<img alt="Logo" src="static/react-editor-js.png" width="100%">
33
</div>
44

5-
<div align="center">
5+
<br>
6+
7+
<div>
68

79
[![npm version](https://badge.fury.io/js/react-editor-js.svg)](https://badge.fury.io/js/react-editor-js)
810
![LICENSE](https://img.shields.io/npm/l/react-editor-js?color=blue)
@@ -13,7 +15,7 @@
1315

1416
## 🍞 DEMO
1517

16-
- [CodeSandbox](https://codesandbox.io/embed/react-editor-js-23opz)
18+
- [CodeSandbox](https://codesandbox.io/s/github/Jungwoo-An/react-editor-js/tree/master/examples)
1719

1820
## 🍀 Supported Official Plugin
1921

@@ -39,28 +41,24 @@
3941
### Install via npm (or yarn)
4042

4143
```bash
42-
# editorjs and official plugins
43-
npm install --save-dev react-editor-js @editorjs/editorjs @editorjs/paragraph
44+
npm install --save react-editor-js @editorjs/editorjs @editorjs/paragraph ...other plugins
4445
```
4546

46-
### Usage
47-
48-
```js
49-
import EditorJs from 'react-editor-js';
47+
```tsx
48+
import EditorJs from 'react-editor-js'
5049

51-
<EditorJs data={data} />;
50+
<EditorJs defaultValue={blocks} />
5251
```
5352

5453
## 📙 API
5554

5655
Allow all options of [editor-js](https://github.com/codex-team/editor.js/blob/master/types/configs/editor-config.d.ts)
5756

58-
| Name | Type | Description |
59-
| ------------------ | ------------------------------------------------------------------------------- | ------------------------------------------------------------------ |
60-
| enableReInitialize | Boolean | Change editor-js data when componentDidUpdate |
61-
| onChange | (api: API, newData: OutputData) => void | Fires when something changed in DOM |
62-
| onCompareBlocks | (newBlocks?: OutputData['blocks'], oldBlocks?: OutputData['blocks']) => boolean | Use to avoid Infinite update when enableReInitialize used with onChange ([Recommended Library](https://github.com/FormidableLabs/react-fast-compare)) |
63-
| onReady | (instance?: EditorJS) => void | Use to execute callback when editor-js instance has initialized |
57+
| Name | Type | Description |
58+
| ------------------ | ------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- |
59+
| defaulltValue | OutputData | Initial data when using editor js as [uncontrolled component](https://ko.reactjs.org/docs/uncontrolled-components.html). highly recommend it |
60+
| value | OutputData | data when using editor js as [controlled component](https://ko.reactjs.org/docs/forms.html#controlled-components). <br> ⚠️ Don't use it with onChange prop as much as possible. Infinite loops can occur. |
61+
| onInitialize | (editorJS?: EditorJS) => void | Call after editor-js is initialized |
6462

6563
## 🧐 FAQ
6664

@@ -74,11 +72,11 @@ To add more Block Tools, simply add them to your repo and pass them as `tools`-p
7472
npm install --save-dev @editorjs/checklist
7573
```
7674

77-
```js
78-
import EditorJs from 'react-editor-js';
79-
import CheckList from '@editorjs/checklist';
75+
```tsx
76+
import EditorJs from 'react-editor-js'
77+
import CheckList from '@editorjs/checklist'
8078

81-
<EditorJs data={data} tools={{ checkList: CheckList }} />;
79+
<EditorJs defaultValue={blocks} tools={{ checkList: CheckList }} />
8280
```
8381

8482
We recommend to create a `tools.js` file and export your tools as a constant. Here is an example using all of the default plugins:
@@ -118,49 +116,45 @@ export const EDITOR_JS_TOOLS = {
118116
checklist: CheckList,
119117
delimiter: Delimiter,
120118
inlineCode: InlineCode,
121-
simpleImage: SimpleImage
119+
simpleImage: SimpleImage,
122120
}
123121
```
124122

125123
```tsx
126-
import EditorJs from 'react-editor-js';
124+
import EditorJs from 'react-editor-js'
127125
import { EDITOR_JS_TOOLS } from './tools'
128-
<EditorJs data={data} tools={EDITOR_JS_TOOLS} />;
129-
```
130126

127+
<EditorJs defaultValue={blocks} tools={EDITOR_JS_TOOLS} />
128+
```
131129

132130
You can read more about plugins/tools at [editor-js: Tools installation](https://editorjs.io/getting-started#tools-installation)
133131

134132
### How do I use custom element?
135133

136134
It's simpleeeee
137135

138-
```js
139-
render() {
140-
return (
141-
<EditorJs holder="custom">
142-
<div id="custom" />
143-
</EditorJs>
144-
);
145-
}
136+
```tsx
137+
<EditorJs holder="custom">
138+
<div id="custom" />
139+
</EditorJs>
146140
```
147141

148142
### How to access editor-js instance?
149143

150144
You can access using instanceRef
151145

152-
```js
153-
async handleSave() {
154-
const savedData = await this.editorInstance.save();
155-
}
146+
```tsx
147+
const editorJS = React.useRef(null)
156148

157-
componentDidMount() {
158-
this.editorInstance // access editor-js
159-
}
149+
const handleInitialize = React.useCallback((instance) => {
150+
editorJS.current = instance
151+
}, [])
160152

161-
render() {
162-
return <EditorJs instanceRef={instance => this.editorInstance = instance} data={data} />
163-
}
153+
const handleSave = React.useCallback(() => {
154+
const savedData = await editorJS.current.save();
155+
}, [])
156+
157+
<EditorJs onInitialize={handleInitialize} defaultValue={blocks} />
164158
```
165159

166160
### Haven't received data from server (when use Link)
@@ -170,17 +164,15 @@ You should set linkTool [config](https://github.com/editor-js/link#usage). 💪
170164
```tsx
171165
import LinkTool from '@editorjs/link'
172166

173-
render() {
174-
<EditorJs
175-
data={data}
176-
tools={{
177-
linkTool: {
178-
class: LinkTool,
179-
config: {
180-
endpoint: 'http://localhost:8008/fetchUrl', // Your backend endpoint for url data fetching
181-
}
167+
<EditorJs
168+
defaultValue={blocks}
169+
tools={{
170+
linkTool: {
171+
class: LinkTool,
172+
config: {
173+
endpoint: 'http://localhost:8008/fetchUrl', // Your backend endpoint for url data fetching
182174
}
183-
}}
184-
/>
185-
}
175+
}
176+
}}
177+
/>
186178
```

static/react-editor-js.png

-60 KB
Loading

0 commit comments

Comments
 (0)