I'am trying to call a callback function in the parent, which is triggered inside the child component. I already tried the different ways of binding, but I still can't get it to work. I always get this error.
Cannot read property 'logMessage' of undefined
My Parent
logMessage() {
console.log("logMessage was called");
}
return(
<div>
<h1>Blogs</h1>
{this.state.campaigns.map(function(blog) {
return (
<div key={blog._id}>
<CampaignCard blog={blog} callBack={() => this.logMessage()} />
</div>
);
})}
<Link to="/campaigns/add">
<button>Add Blog</button>
</Link>
</div>
);
My child
onConfirm={() => {
this.setState({ show: false });
this.props.callBack();
}}
I can see that the callback function is called, but it still seems like this
does not reference to the right place.