I am currently creating a damage calculator app with React. I am just starting out so bear with me.
Here is my code for getting the input value of 'Atk'. This is currently in my component called 'CalculatorItems':
class Atk extends Component {
constructor(props) {
super(props);
this.state = {stats: ''}
}
render() {
return (
<div>
<label>PHY/MAG ATK</label><br/>
<input value={this.state.stats}
onChange={event => this.setState({stats: event.target.value})}
type="number"
/>
<br/><br/>
</div>
)
}
}
Now I created a function to be called whenever the 'Calculate Damage' button is clicked. In this function, I need to assign variable 'A' to the input value of the above 'Atk'. This is in the parent component called 'Calculator'.
const damageCalc = () => {
let A = (Class Atk's input value).
My question is what am I supposed to write in the parenthesis so that I can assign the variable A to Atk's input value/state? Would work?
Keep in mind this is in another component since I need to apply the function to CalculatorButton's onClick (CalculatorButton is another child component).