0

I have seen { props } = this, within the following piece of code. What is this used?

render = () => {
        const { props } = this

  • 3
    Object destructuring: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment#object_destructuring – Lesiak Feb 22 '21 at 13:18
  • 3
    Does this answer your question? [When should I use "this" in a class?](https://stackoverflow.com/questions/2411270/when-should-i-use-this-in-a-class) – Terminat Feb 22 '21 at 13:19

1 Answers1

3

This is not a feature of React. This is the destructuring syntax of JS. Any object which looks like the following :-

let obj = {name:'Arjunan'}

can be destructured to access name property like :-

const {name} = obj

In your question, this is the object created using your React class constructor and the property props exist on it.

Lakshya Thakur
  • 8,030
  • 1
  • 12
  • 39