I'm new to react and I'm having a problem on how getting onclick value of another component.
2 Answers
Call your button component over here and pass your function through props to button component.
function should be:->
handleClick(letter) {
return letter;
}
//button component
<button click={this.handleClick} value="getLetterValue" />
Through this you will get the value of letter. Hope this will resolve your issue, if won't than you can contact me again. Its all my pleasure to help you.

- 759
- 6
- 9
It depends where are you rendering that button.js file
- If you call YourButton on the same List component then you can just set a prop and pass it down.
handleClick(letter) { this.myLetter = letter; }
render() {
`<YourButton letter={this.myLetter} />`
}
And inside YourButton you will have this.prop.letter available.
If YourButton is not a child, then you will have to get the prop on the parent:
handleClick(letter) { this.props.myParentClickEvent(letter) }
Then on the parent:
myParentClickEvent(letter) {
this.myLetter = letter;
}
And then pass it down to any children you want as a prop.
This second step is a bit more complicated so I recommend you to first read the documentation to completely understand how props work on React as it is an essential part if you want to continue working with it.

- 2,138
- 1
- 15
- 14