I am learning react and I am following the quick start guide, In the topic Lifting State Up I found the Calculator component
class Calculator extends React.Component {
constructor(props) {
super(props);
...
this.state = {scale: 'c', temperature: ''}
}
handleCelsiusChange(temperature) {
this.setState({scale: 'c', temperature})
}
handleFahrenheitChange(temperature) {
this.setState({scale: 'f', temperature});
}
render() {
...
return (
<div>
...
</div>
)
}
}
My question is about this sentence this.setState({scale: 'c', temperature}) here I am expecting this.setState({scale: 'c', temperature: temperature}).
Is this temperature assignation some react sintax sugar? Could you please explain me why this works.
Thanks
setState(). This is syntax for the object literal as described in the answers.