Answer the question
In order to leave comments, you need to log in
Why is the entry in setState not in the standard syntax?
Here the temperature is strangely set, why so?this.setState({scale: 'c', temperature});
class Calculator extends React.Component {
constructor(props) {
super(props);
this.handleCelsiusChange = this.handleCelsiusChange.bind(this);
this.handleFahrenheitChange = this.handleFahrenheitChange.bind(this);
this.state = {temperature: '', scale: 'c'};
}
handleCelsiusChange(temperature) {
this.setState({scale: 'c', temperature});
}
handleFahrenheitChange(temperature) {
console.log(temperature)
this.setState({scale: 'f', temperature});
}
Answer the question
In order to leave comments, you need to log in
ES6. This means temperature is the key and value from the temperature variable, i.e. { temperature: temperature } in ES5
const test = true
const obj = { test } //> { test: true }
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question