In the case of this code, I have to click the calculate button twice to find answers of BMI and BMI judge. How to code it to click only once find the two answers?
bmiCalc (){ this.setState({bmi:this.state.weight/(this.state.height*this.state.height)*10000}); if(this.state.bmi<18.5){this.setState({judge: 'Underweight'});} else if(this.state.bmi<24.9){this.setState({judge:'Normal weight'});} else if(this.state.bmi<30){this.setState({judge:'Overweight'});} else{this.setState({judge:'Obesity'});} } render(){ return ( <ul><button onClick={this.bmiCalc.bind(this)}>calculate</button></ul> <ul>BMI: {Math.round(this.state.bmi*10)/10}</ul> <ul>BMI judge :{this.state.judge} </ul> ); }
render()returns multiple elements, they're not an array, not even separated by commas. Not to mention that React forbidsrender()from returning multiple root elements.