![](/img/trans.png)
[英]ReactJS DataCloneError: Failed to execute 'pushState' on 'History': MouseEvent object could not be cloned
[英]Failed to execute 'pushState' on 'History': function addComment() … could not be cloned
我试图在React中制作我的第一个应用程序,但我认为我在应用程序流程中犯了一些严重的错误,但是尝试保存它并不能使其更好。
我有我的App.ksin
<LatestRecipes latestRecipes={this.state.latestRecipes} allRecipes={this.state.recipes} addComment={this.addComment}/>
现在,AddComment仅是:
addComment(key, commentData)
{
console.log(key);
console.log(commentData);
}
在最新的食谱中,我有:
<Link to={{pathname: '/recipe/' + recipe.name, state: { recipe: recipe, index: index, addComment: this.props.addComment }}}>{recipe.name}</Link>
这给了我错误:
无法在“历史记录”上执行“ pushState”:函数addComment()...无法克隆。
导致错误的是参数: addComment: this.props.addComment
如果删除它,一切正常,但是我需要将功能传递给我的Recipe组件。 在App.js中
<Route path="/recipe/:recipe" component={Recipe}/>
我需要传递所有三个参数,配方,索引和函数addComment()
更改:
<Route path="/recipe/:recipe" component={Recipe}/>
至:
<Route path="/recipe/:recipe" render={(props) => <Recipe {...props} addComment={this.addComment}/>} />
在我的App.js中解决了它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.