diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 8288ba6..9a4af41 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -5,6 +5,7 @@ on: [push] jobs: install: runs-on: ubuntu-latest + if: "! contains(github.event.head_commit.message, '[skip ci]')" steps: - uses: actions/checkout@v1 - uses: actions/setup-node@v1 diff --git a/README.md b/README.md index 8f9c9fc..481b023 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,10 @@
-[![npm version](https://badge.fury.io/js/react-editor-js.svg)](https://badge.fury.io/js/react-editor-js) ![NPM](https://img.shields.io/npm/l/react-editor-js) ![GitHub Workflow Status](https://img.shields.io/github/workflow/status/Jungwoo-An/react-editor-js/release) +[![npm version](https://badge.fury.io/js/react-editor-js.svg)](https://badge.fury.io/js/react-editor-js) +![LICENSE](https://img.shields.io/npm/l/react-editor-js?color=blue) +[![Github Build Status](https://github.com/Jungwoo-An/react-editor-js/workflows/release/badge.svg)](https://github.com/Jungwoo-An/react-editor-js/actions) +[![Semantic Release enabled](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)
@@ -54,7 +57,7 @@ Allow all options of [editor-js](https://github.com/codex-team/editor.js/blob/ma | Name | Type | Description | | ------------------ | ------- | --------------------------------------------- | -| enableReInitialize | Boolean | editor-js rerendering when componentDidUpdate | +| enableReInitialize | Boolean | Change editor-js data when componentDidUpdate | ## 🧐 FAQ diff --git a/lib/EditorJs.tsx b/lib/EditorJs.tsx index d39e394..f2b6d90 100644 --- a/lib/EditorJs.tsx +++ b/lib/EditorJs.tsx @@ -1,6 +1,6 @@ import * as React from 'react' -import EditorJS from '@editorjs/editorjs' +import EditorJS, { OutputData } from '@editorjs/editorjs' import Paragraph from '@editorjs/paragraph' export interface EditorJsProps { @@ -20,14 +20,12 @@ class EditorJsContainer extends React.PureComponent { } async componentDidUpdate() { - const { enableReInitialize } = this.props - if (!enableReInitialize) { + const { enableReInitialize, data } = this.props + if (!enableReInitialize || !data) { return } - await this.destroyEditor() - - this.initEditor() + this.changeData(data); } componentWillUnmount() { @@ -84,6 +82,19 @@ class EditorJsContainer extends React.PureComponent { }) } + changeData(data: OutputData) { + if (!this.instance) { + return; + } + + this.instance?.isReady.then(() => { + this.instance!.clear(); + this.instance!.render(data); + }).catch(() => { + // do nothing + }); + } + render() { const { children } = this.props diff --git a/package.json b/package.json index 04506f3..efac2fd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-editor-js", - "version": "1.4.4", + "version": "1.5.0", "description": "The unofficial editor-js component for React", "author": "Jungwoo An ", "keywords": [