0

What is the difference between these two lines of code?

let { fadeAnim } = this.state;

vs

let fadeAnim = this.state;?
Mayank Shukla
  • 92,299
  • 16
  • 152
  • 142
Patt
  • 11
  • 2

2 Answers2

0

If this.state is a reference to an object, then

let { fadeAnim } = this.state;

is like

let fadeAnim = this.state.fadeAnim;

It's a destructuring assignment that implicitly extracts one or more properties from an object (just one in this case).

Pointy
  • 389,373
  • 58
  • 564
  • 602
0
let { fadeAnim } = this.state;

Equals

let fadeAnim = this.state.fadeAnim;

It’s called destructuring assignment: https://developer.mozilla.org/nl/docs/Web/JavaScript/Reference/Operatoren/Destructuring_assignment

Koen.
  • 23,152
  • 6
  • 79
  • 76