Reputation: 173
I have to pass function through Link to another component.
testFavorite=()=>{
console.log("work")
}
<Link
to={{
pathname: '/popular',
state:{
testFavorite: this.testFavorite
}
}}>
Popular</Link>
This is how I call a function
this.props.location.state.testFavorite();
But i have this error
history.js:370 Uncaught DOMException: Failed to execute 'pushState' on 'History': function () { console.log("work"); } could not be cloned.
How can i fix it? Thank you a lot
Upvotes: 0
Views: 2930
Reputation: 59
It can be done when you replace state with Data.
<Link
to={{
pathname: '/popular',
data:{
testFavorite: this.testFavorite
}
}}>
Also replace here
this.props.location.state.testFavorite();
Meanwhile, if you also want to pass data as props you can use state along with data
Upvotes: 2