Javascript 重复道具问题

Javascript 重复道具问题,javascript,reactjs,react-redux,react-redux-form,Javascript,Reactjs,React Redux,React Redux Form,我有一个显示票证详细信息的页面,包括它的评论,这个页面有一个简单的表单,可以在这个票证下创建评论。 已成功提交表单并添加评论。 问题 当我将当前票证页面转到另一个票证页面时,我为第一张票证创建的注释将显示在第二张票证的页面中 表格 <form onSubmit={this.handleAddComment} className="m-form"> <div className="group-

我有一个显示票证详细信息的页面,包括它的评论,这个页面有一个简单的表单,可以在这个票证下创建评论。 已成功提交表单并添加评论。
问题
当我将当前票证页面转到另一个票证页面时,我为第一张票证创建的注释将显示在第二张票证的页面中

表格

                    <form onSubmit={this.handleAddComment} className="m-form">
                        <div className="group-control">
                            <textarea 
                                className="form-control" 
                                value={this.state.comment} 
                                name="comment"  
                                onChange={this.handleChange}
                                required
                            >
                            </textarea>
                        </div>
                        <br />
                        <div className="m-widget13__action m--align-right">
                            <button type="submit" className="btn btn-primary">
                                Add Comment
                            </button>
                        </div>
                    </form>
创建评论后,我检查组件中接收到的内容是否会接收

componentWillReceiveProps(nextProps)
{
    if(nextProps.createComment.comment)
    {
        // append created to comment to comments array
        this.setState({
            comments : this.state.comments.concat(nextProps.createComment.comment)
        })
        swal({ title: 'Success', type : "success", text: 'Comment created successfully!', timer: 3000});
    }
}
经过一些跟踪以解决问题:我发现componentWillReceiveProps方法仍然保留创建的注释的数据,而不是我更改了票证页面


我该怎么处理这个问题呢?

nextrops.createComment.comment的结果是什么?还可以在
componentdiddupdate
中尝试该逻辑,还有什么是
comments
,一个数组?@Amir Mousavi comments===>与票证相关的注释数组,nextrops.createComment.comment===>string1的结果。而不是concat
推到comments数组。2.不清楚在代码中的何处清除状态中的注释。我建议在
手动提示的末尾清除状态。从道具来看(除非我们看到整个结构),很难说
willReceiveProps
是否存在问题。同样如前所述,
willreceiveprops
是不安全的,使用
diddupdate
代替
nextrops.createComment.comment
的结果是什么?还可以在
componentdiddupdate
中尝试该逻辑,还有什么是
comments
,一个数组?@Amir Mousavi comments===>与票证相关的注释数组,nextrops.createComment.comment===>string1的结果。而不是concat
推到comments数组。2.不清楚在代码中的何处清除状态中的注释。我建议在
手动提示的末尾清除状态。从道具来看(除非我们看到整个结构),很难说
willReceiveProps
是否存在问题。如前所述,
willreceiveprops
是不安全的,使用
diddupdate
componentWillReceiveProps(nextProps)
{
    if(nextProps.createComment.comment)
    {
        // append created to comment to comments array
        this.setState({
            comments : this.state.comments.concat(nextProps.createComment.comment)
        })
        swal({ title: 'Success', type : "success", text: 'Comment created successfully!', timer: 3000});
    }
}