Skip to content

Commit

Permalink
feat: Randomize holder id (#76) [ci skip]
Browse files Browse the repository at this point in the history
* Randomize holder id

* Make PR #76 code review changes

* Class field for holder, no constructor
  • Loading branch information
jakekara authored Nov 28, 2020
1 parent 5c1806e commit 19b1c64
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions lib/EditorJs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ export type Props = Readonly<EditorJS.EditorConfig> & Readonly<EditorJsProps>

class EditorJsContainer extends React.PureComponent<Props> {
instance?: EditorJS
holder: string = `editor-js-${(
Math.floor(Math.random() * 1000) + Date.now()
).toString(36)}`

componentDidMount() {
this.initEditor()
Expand Down Expand Up @@ -68,19 +71,19 @@ class EditorJsContainer extends React.PureComponent<Props> {
// default tools
paragraph: {
class: Paragraph,
inlineToolbar: true
inlineToolbar: true,
},
...tools
...tools,
}

this.instance = new EditorJS({
tools: extendTools,
holder: 'editor-js',
holder: this.holder,

...(onChange && {
onChange: this.handleChange
onChange: this.handleChange,
}),
...props
...props,
})

if (instanceRef) {
Expand Down Expand Up @@ -126,7 +129,7 @@ class EditorJsContainer extends React.PureComponent<Props> {
render() {
const { children } = this.props

return children || <div id="editor-js" />
return children || <div id={this.holder} />
}
}

Expand Down

0 comments on commit 19b1c64

Please sign in to comment.