Skip to content

Commit d243539

Browse files
feat: add onReady property (#91)
1 parent a24f513 commit d243539

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
node_modules
2-
.rpt2_cache
2+
.rpt2_cache

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ Allow all options of [editor-js](https://github.com/codex-team/editor.js/blob/ma
6060
| enableReInitialize | Boolean | Change editor-js data when componentDidUpdate |
6161
| onChange | (api: API, newData: OutputData) => void | Fires when something changed in DOM |
6262
| 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 |
6364

6465
## 🧐 FAQ
6566

lib/EditorJs.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export interface EditorJsProps {
99
instanceRef?: (instance: EditorJS) => void
1010

1111
onChange?: (api: API, data?: OutputData) => void
12+
onReady?: (instance?: EditorJS) => void,
1213
onCompareBlocks?: (
1314
newBlocks: BlockToolData | undefined,
1415
oldBlocks: BlockToolData | undefined
@@ -62,13 +63,23 @@ class EditorJsContainer extends React.PureComponent<Props> {
6263
onChange(api, newData)
6364
}
6465

66+
handleReady = () => {
67+
const { onReady } = this.props
68+
if (!onReady) {
69+
return
70+
}
71+
72+
onReady(this.instance)
73+
}
74+
6575
initEditor() {
6676
const {
6777
instanceRef,
6878
children,
6979
enableReInitialize,
7080
tools,
7181
onChange,
82+
onReady,
7283
...props
7384
} = this.props
7485

@@ -85,6 +96,10 @@ class EditorJsContainer extends React.PureComponent<Props> {
8596
tools: extendTools,
8697
holder: this.holder,
8798

99+
...(onReady && {
100+
onReady: this.handleReady,
101+
}),
102+
88103
...(onChange && {
89104
onChange: this.handleChange,
90105
}),

0 commit comments

Comments
 (0)