In a React sample app I've seen this:
class Calculator extends React.Component {
constructor(props) {
super(props);
this.state = {temperature: '', scale: 'c'};
}
handleCelsiusChange(temperature) {
this.setState({scale: 'c', temperature});
}
}
It isn't clear to me how this line of code works:
this.setState({scale: 'c', temperature});
The state is defined in the constructor like a JSON object:
this.state = {temperature: '', scale: 'c'};
where it has a "temperature" and a "scale" field. But setState is called, the scale member is specified along with the value. But the temperature field's name is not specified. Only its value. Is this a Javascript thing or a React thing? I'm not used to seeing a field's value specified without the field's name. How is React or Javascript suppose to know what field to apply the temperature value to?