首页 > 解决方案 > Quill(react markdown)编辑器在最初使用 props 值渲染时重新渲染。这正常吗?

问题描述

这似乎是不必要的重新渲染。发生这种情况正常吗?为什么它不在一次渲染中做到这一点?

我指的是以下编辑器:https ://quilljs.com/docs/quickstart/


class Editor extends React.Component {
  constructor(props) {
    super(props);
    this.timeout = 0;
    this.state = { text: this.props.description }; // You can also pass a Quill Delta here
    this.handleChange = this.handleChange.bind(this);
  }

  handleChange(value) {
    this.setState({ text: value });

    if (this.timeout) clearTimeout(this.timeout);
    this.timeout = setTimeout(() => {
      this.props.addDescription(value);
    }, 1000);
  }

  

  render() {
    return (
      <div className="text-editor">
        <ReactQuill
          value={this.state.text}
          onChange={this.handleChange}
          modules={this.modules}
          formats={this.formats}
          placeholder={'Write a Description'}
        />
      </div>
    );
  }
}

export default Editor;

标签: reactjsquill

解决方案


推荐阅读