I don't know why but I cannot set an onClick function for a function from the parent that I want to pass to my child component. This is the code from the parent:
_renderChatFriend() {
return([...this.state.friendsNames].map( friend => {
return (<ChatFriendPopUp
onChatFriendPopUpClick={this.popUpMessage}
key={friend.id}
name={friend.name}
/>)
}))
}
and the code on the child component:
class ChatFriendPopUp extends Component {
popUpMessage(name) {
console.log("name clicked ",name)
}
render() {
return (
<li onClick={this.props.onChatFriendPopUpClick(this.props.name)}>{this.props.name}</li>
)
}
}
The onClick is invoked upon mount? and when I click it's not invoked? but I can invoke it by onClick if I don't pass an argument on it. A code like this but I cannot have referrence:
<li onClick={this.props.onChatFriendPopUpClick}> // not passing argument works?