Hi, I want to change my temp by click to buttons c and f. I made checker, so if it’s true temp convert to farenheit else to celcium. But it does not works.
If you find a solution how to fix it please comment below. Thanks =)
All I can see in your methods is to toggle between the checker
state:
CelcConvert() {
this.setState({
checker: true
});
}
FarenConvert() {
this.setState({
checker: false
});
}
I don’t see any update in the temperature value.
Why not a simple:
CelcConvert() {
this.setState({
checker: true,
temp: Celc(this.state.temp)
});
}
should probably be enough.
I’ve tried written like this
CelcConvert( ) {
this.setState({
temp: Celc(this.state.temp)
})
but if I pressed two times the value of temp is increased
It’s hard to pin down the error just by looking at a snippet of code.
In order to better help you it’s better if you could provide a workable example online.
Anyway to help you get started I created a quick demo of a component that convert temperature.
It’s not the most elegant solution by any means but should give you an idea of how to keep the state tracked: