D
D
danilr2019-05-27 12:36:15
React
danilr, 2019-05-27 12:36:15

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

1 answer(s)
I
Ihor Bratukh, 2019-05-27
@danilr

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 question

Ask a Question

731 491 924 answers to any question