Skip to content

Commit

Permalink
fix: force update state to re-render <ReactQuill>
Browse files Browse the repository at this point in the history
  • Loading branch information
robertu7 committed Dec 30, 2022
1 parent e7d44c7 commit 21a1e3d
Showing 3 changed files with 21 additions and 18 deletions.
4 changes: 2 additions & 2 deletions demo/index.tsx
Original file line number Diff line number Diff line change
@@ -97,7 +97,7 @@ const App = () => {
titleDefaultValue=""
titleReadOnly={false}
/>
{/*

<br />

<MattersCommentEditor
@@ -114,7 +114,7 @@ const App = () => {
texts={{
COMMENT_PLACEHOLDER: 'custom placeholder\nand line break',
}}
/> */}
/>
</>
)
}
4 changes: 2 additions & 2 deletions src/article.tsx
Original file line number Diff line number Diff line change
@@ -234,7 +234,7 @@ export class MattersArticleEditor extends React.Component<Props, State> {
texts: this.texts,
},
mention: {
mentionContainer: this.mentionReference.current,
mentionContainer: this.mentionReference?.current,
handleMentionChange: this.handleMentionChange,
storeMentionInstance: this.storeMentionInstance,
},
@@ -261,7 +261,7 @@ export class MattersArticleEditor extends React.Component<Props, State> {
update={this.props.editorUpdate}
/>
<div id="editor-article-container" className={classes}>
{this.mentionReference.current && (
{this.mentionReference?.current && (
<ReactQuill
formats={FORMAT_CONFIG}
modules={modulesConfig}
31 changes: 17 additions & 14 deletions src/comment.tsx
Original file line number Diff line number Diff line change
@@ -113,8 +113,7 @@ export class MattersCommentEditor extends React.Component<Props, State> {
const modulesConfig = {
...MODULE_CONFIG,
mention: {
mentionContainer:
this.mentionReference && this.mentionReference.current,
mentionContainer: this.mentionReference?.current,
handleMentionChange: this.handleMentionChange,
storeMentionInstance: this.storeMentionInstance,
},
@@ -123,25 +122,29 @@ export class MattersCommentEditor extends React.Component<Props, State> {
return (
<>
<div id="editor-comment-container">
<ReactQuill
formats={FORMAT_CONFIG}
modules={modulesConfig}
placeholder={this.texts.COMMENT_PLACEHOLDER}
readOnly={this.props.readOnly}
ref={this.editorReference}
theme={this.props.theme}
value={this.state.content}
onChange={this.handleChange}
bounds="#editor-comment-container"
scrollingContainer={this.props.scrollingContainer}
/>
{this.mentionReference?.current && (
<ReactQuill
formats={FORMAT_CONFIG}
modules={modulesConfig}
placeholder={this.texts.COMMENT_PLACEHOLDER}
readOnly={this.props.readOnly}
ref={this.editorReference}
theme={this.props.theme}
value={this.state.content}
onChange={this.handleChange}
bounds="#editor-comment-container"
scrollingContainer={this.props.scrollingContainer}
/>
)}

<MattersEditorMention
mentionLoading={this.props.mentionLoading}
mentionListComponent={this.props.mentionListComponent}
mentionSelection={this.handleMentionSelection}
mentionUsers={this.props.mentionUsers}
reference={this.mentionReference}
// FIXME: force update state to re-render <ReactQuill>
onMount={() => this.setState({ content: this.state.content })}
/>
</div>
</>

0 comments on commit 21a1e3d

Please sign in to comment.