0

what is the difference between the following in React?

this.setState({[name]: value }) 

and

this.setState({name: value });
Paul Fitzgerald
  • 11,770
  • 4
  • 42
  • 54
John
  • 217
  • 1
  • 3
  • 11
  • One sets `this.state.name` to `value`, the other sets `this.state[name]` to `value`. – jonrsharpe Nov 12 '18 at 11:35
  • Yes but what is the difference. Because when I'm writing only name without bracket I having errors – John Nov 12 '18 at 11:39
  • That *is* the difference. If you still have a specific problem after reading the duplicate please [edit] to give a [mcve], not just *"having errors"*. – jonrsharpe Nov 12 '18 at 11:44

0 Answers0