0

What is the difference between these two lines of code?

let { fadeAnim } = this.state;

vs

let fadeAnim = this.state;?
Mayank Shukla
  • 100,735
  • 18
  • 158
  • 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
  • 405,095
  • 59
  • 585
  • 614
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.
  • 25,449
  • 7
  • 83
  • 78