Failed to execute 'pushState' on 'History': function addComment() … could not be cloned

十年热恋 提交于 2021-01-29 16:13:43

问题


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.

I got my App.ksin which I have

<LatestRecipes latestRecipes={this.state.latestRecipes} allRecipes={this.state.recipes} addComment={this.addComment}/>

Right now AddComment is only:

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.

What creates the error is the argument: addComment: this.props.addComment

if I remove it everything works but I need to pass my function thos to my Recipe component. Which is in App.js

<Route path="/recipe/:recipe" component={Recipe}/>

Which I need to pass all three arguments, recipe, index and the function addComment()


回答1:


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.



来源:https://stackoverflow.com/questions/52786072/failed-to-execute-pushstate-on-history-function-addcomment-could-not

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!