[英]Failed to execute 'pushState' on 'History': function addComment() … could not be cloned
I've tried to make my first app in React and I think I've made some serious error in the flow of the Application however trying to save it doesn't make it better. 我试图在React中制作我的第一个应用程序,但我认为我在应用程序流程中犯了一些严重的错误,但是尝试保存它并不能使其更好。
I got my App.ksin which I have 我有我的App.ksin
<LatestRecipes latestRecipes={this.state.latestRecipes} allRecipes={this.state.recipes} addComment={this.addComment}/>
Right now AddComment is only: 现在,AddComment仅是:
addComment(key, commentData)
{
console.log(key);
console.log(commentData);
}
And in latest Recipe I have: 在最新的食谱中,我有:
<Link to={{pathname: '/recipe/' + recipe.name, state: { recipe: recipe, index: index, addComment: this.props.addComment }}}>{recipe.name}</Link>
This gives me the error: 这给了我错误:
Failed to execute 'pushState' on 'History': function addComment() ... could not be cloned.
无法在“历史记录”上执行“ pushState”:函数addComment()...无法克隆。
What creates the error is the argument: addComment: this.props.addComment
导致错误的是参数:
addComment: this.props.addComment
if I remove it everything works but I need to pass my function thos to my Recipe component. 如果删除它,一切正常,但是我需要将功能传递给我的Recipe组件。 Which is in App.js
在App.js中
<Route path="/recipe/:recipe" component={Recipe}/>
Which I need to pass all three arguments, recipe, index and the function addComment() 我需要传递所有三个参数,配方,索引和函数addComment()
Changing: 更改:
<Route path="/recipe/:recipe" component={Recipe}/>
to: 至:
<Route path="/recipe/:recipe" render={(props) => <Recipe {...props} addComment={this.addComment}/>} />
In my App.js solved it. 在我的App.js中解决了它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.