I am Trying to make a Simple React BMI Calculator. I am trying to implement something like when ı click the submit button i want to create new html at the bottom like
your body index is {yourindex}
everytime that i click the submit button. You can think same like in todo apps.How can ı do that ? Thanks
import React, { Component } from 'react'
class Areas extends Component {
constructor(props) {
super(props)
this.state = {
kg:0,
height:0,
}
this.updateKG = this.updateKG.bind(this)
this.updateHeight = this.updateHeight.bind(this)
this.calculateBMI = this.calculateBMI.bind(this)
}
updateKG(event){
this.setState({kg:event.target.value})
}
updateHeight(event){
this.setState({height:event.target.value})
}
calculateBMI(){
this.state.totals.push(parseInt(this.state.kg) + parseInt(this.state.height))
console.log(this.state.totals)
}
render() {
return (
<div>
<div className="jumbotron text-center mt-3">
<div className="container">
<h1 className="display-4">Calculate Your BMI</h1>
<p className="lead">Calculate How fat you are ?</p>
</div>
</div>
<div className="container mt-5">
<div className="row">
<div className="col text-center">
<p>Your Kg</p>
<input type="number" min="30" onChange={this.updateKG}/>
</div>
<div className="col text-center">
<p>Your Height in cm</p>
<input type="number" min="60" onChange={this.updateHeight}/>
</div>
<div className="col text-center">
<p>Calculate Your BMI</p>
<button className="btn btn-success" type="submit" onClick={this.calculateBMI}>Submit</button>
</div>
</div>
</div>
</div>
)
}
}
export default Areas
divor component based on the state. I personally prefer display portion to be a separate component but it's a design decision and irrelevant to code.{kg: value, height: value}.