In my current calculator project (https://codepen.io/Crimson_Macaw/pen/JeMeEP) I’m trying to get the handleClick function to take in a div’s id as its argument. The snippet is below:
class Buttons extends React.Component{
runParentHandleClick = () => {
this.props.handleClick(id)
}
render(){
return(
<div className = "buttonRows">
<div className = "rowOne" onClick = {this.runParentHandleClick} id = "nine" data-id = "nine">9</div>
<div className = "rowOne" onClick = {this.runParentHandleClick} id = "eight" data-id = "eight">8</div>
<div className = "rowOne" onClick = {this.runParentHandleClick} id = "seven">7</div>
<div className = "rowOne" onClick = {this.runParentHandleClick} id = "six">6</div>
</div>
)
}
}
This is the only way I’ve figured out how to pass a unique argument into the handleClick function so that it can then display the number in the calculator screen. The problem is that I don’t know how to write the syntax for it properly.
If anyone has any ideas on other ways that I could achieve this (without passing in the div’s id) I’m open to trying them out as well.