[英]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.