Skip to content

Commit 21f2150

Browse files
committed
docs: Update README for changed API [skip ci] (#166)
1 parent 2d19334 commit 21f2150

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

README.md

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
## 🍞 DEMO
1717

18-
- [CodeSandbox](https://codesandbox.io/s/github/Jungwoo-An/react-editor-js/tree/master/examples)
18+
- [CodeSandbox](https://codesandbox.io/s/react-editor-js-v2-34bfl)
1919

2020
## 🍀 Supported Official Plugin
2121

@@ -45,9 +45,11 @@ npm install --save react-editor-js @editorjs/editorjs @editorjs/paragraph ...oth
4545
```
4646

4747
```tsx
48-
import EditorJs from 'react-editor-js'
48+
import { createReactEditorJS } from 'react-editor-js'
4949

50-
<EditorJs defaultValue={blocks} />
50+
const ReactEditorJS = createReactEditorJS()
51+
52+
<ReactEditorJS defaultValue={blocks} />
5153
```
5254

5355
## 📙 API
@@ -57,7 +59,7 @@ Allow all options of [editor-js](https://github.com/codex-team/editor.js/blob/ma
5759
| Name | Type | Description |
5860
| ------------------ | ------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- |
5961
| 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. |
62+
| 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. Infinite loops can occur. |
6163
| onInitialize | (editorJS?: EditorJS) => void | Call after editor-js is initialized |
6264

6365
## 🧐 FAQ
@@ -73,10 +75,12 @@ npm install --save-dev @editorjs/checklist
7375
```
7476

7577
```tsx
76-
import EditorJs from 'react-editor-js'
78+
import { createReactEditorJS } from 'react-editor-js'
7779
import CheckList from '@editorjs/checklist'
7880

79-
<EditorJs defaultValue={blocks} tools={{ checkList: CheckList }} />
81+
const ReactEditorJS = createReactEditorJS()
82+
83+
<ReactEditorJS defaultValue={blocks} tools={{ checkList: CheckList }} />
8084
```
8185

8286
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:
@@ -101,9 +105,10 @@ import InlineCode from '@editorjs/inline-code'
101105
import SimpleImage from '@editorjs/simple-image'
102106

103107
export const EDITOR_JS_TOOLS = {
108+
// NOTE: Paragraph is default tool. Declare only when you want to change paragraph option.
109+
// paragraph: Paragraph,
104110
embed: Embed,
105111
table: Table,
106-
paragraph: Paragraph,
107112
list: List,
108113
warning: Warning,
109114
code: Code,
@@ -121,10 +126,12 @@ export const EDITOR_JS_TOOLS = {
121126
```
122127

123128
```tsx
124-
import EditorJs from 'react-editor-js'
129+
import { createReactEditorJS } from 'react-editor-js'
125130
import { EDITOR_JS_TOOLS } from './tools'
126131

127-
<EditorJs defaultValue={blocks} tools={EDITOR_JS_TOOLS} />
132+
const ReactEditorJS = createReactEditorJS()
133+
134+
<ReactEditorJS defaultValue={blocks} tools={EDITOR_JS_TOOLS} />
128135
```
129136

130137
You can read more about plugins/tools at [editor-js: Tools installation](https://editorjs.io/getting-started#tools-installation)
@@ -134,9 +141,9 @@ You can read more about plugins/tools at [editor-js: Tools installation](https:/
134141
It's simpleeeee
135142

136143
```tsx
137-
<EditorJs holder="custom">
144+
<ReactEditorJS holder="custom">
138145
<div id="custom" />
139-
</EditorJs>
146+
</ReactEditorJS>
140147
```
141148

142149
### How to access editor-js instance?
@@ -154,7 +161,7 @@ const handleSave = React.useCallback(() => {
154161
const savedData = await editorJS.current.save();
155162
}, [])
156163

157-
<EditorJs onInitialize={handleInitialize} defaultValue={blocks} />
164+
<ReactEditorJS onInitialize={handleInitialize} defaultValue={blocks} />
158165
```
159166

160167
### Haven't received data from server (when use Link)
@@ -164,7 +171,7 @@ You should set linkTool [config](https://github.com/editor-js/link#usage). 💪
164171
```tsx
165172
import LinkTool from '@editorjs/link'
166173

167-
<EditorJs
174+
<ReactEditorJS
168175
defaultValue={blocks}
169176
tools={{
170177
linkTool: {

0 commit comments

Comments
 (0)