[英]onChange for input React JS makes typing render slow
I am making a React page which has a post and comments on the post. 我正在制作一个React页面,其中有帖子和评论。 Now the onChange on being triggered re-renders the whole class which makes the typing in input slow. 现在触发的onChange重新呈现整个类,这使得输入输入变慢。 Now, if the is declared in a separate class and the value entered in the input there can be sent to the main class for API call. 现在,如果在单独的类中声明并且在输入中输入的值,则可以将其发送到主类以进行API调用。 But I am not able to do this. 但我无法做到这一点。 Can anyone help me? 谁能帮我?
Below is code for my comment section of the screen. 下面是我的评论部分的代码。
commentChange(html) {
this.setState({ post_comment: html})
}
<div className="post-comments">
<div className="post-comments-head">
<div>Comments ({this.state.comments.length})</div>
</div>
<div className="comments">
{this.createCommentList(this.state.comments2)}
</div>
</div>
<div className="post-commenting">
{this.state.reply == -1 ? <span>Comment as {this.state.name}</span>
: this.commentBy()}
<div className="write-comment-post">
<ReactQuill
data-gramm_editor="false"
onChange={this.commentChange}
value={this.state.post_comment}
className="post_comments_x"
placeholder="Write a comment"
ref={(ip) => this.myInp = ip}
autoFocus={true}
theme=""
/>
<div className="comments-submit">
<button className="submit-comment"
onClick={() => this.submitComment(this.state.reply)}
disabled={!enabledComment}>
Comment
</button>
</div>
</div>
</div>
The createCommentList function takes comments and returns a nested list of comments. createCommentList函数接受注释并返回嵌套的注释列表。 Below is the section where new comment is added. 以下是添加新评论的部分。 How to solve this because it is making typing a new comment very slow. 如何解决这个问题,因为它使得输入新注释的速度非常慢。
<div className="write-comment-post">
<ReactQuill
data-gramm_editor="false"
onChange={this.commentChange}
value={this.state.post_comment}
className="post_comments_x"
placeholder="Write a comment"
ref={(ip) => this.myInp = ip}
autoFocus={true}
theme=""
/>
create a seperate component for this and only onn enter call parennt function else onchange it will trigger 为此创建一个单独的组件,只有onn进入调用parennt函数,否则它将触发它
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.