-1

What are all the properties that has been passed as props in this es6 destructure ?

const {
      day,
      day: {
        date,
        isCurrentMonth,
        isToday,
        number
      },
      select,
      selected
    } = this.props;
jammy
  • 857
  • 2
  • 18
  • 34

1 Answers1

2

Your props object is something like this

this.props = {
  day: {
    date,
    isCurrentMonth,
    isToday,
    number
  },
  select,
  selected
} 

with props day which is of type object, select which could be number, string, boolean or something else can't really the type from the information you provide, and selected as our last prop.

To destructure, this.props, you do something like this:

 const { day, select, selected } = this.props;

Since day is also an object you can further destructure it like this:

const { date, isCurrentMonth, isToday, number } = day

You can as well call the day object properties on the day object itself

const date = day.date;
const  isCurrentMonth = day.isCurrentMonth;

That piece of code above is similar to the destructuring mentioned earlier.

Simply put by destructuring, you are storing object properties in other variables for ease of access

Isaac Sekamatte
  • 5,500
  • 1
  • 34
  • 40