Destructuring ES6 Deep Nested Objects

I have an object called this.props that contains

 { actions: Object, dirty: false, form: "Statement", autofill: functon(), **statement: Object** } 

statement contains

 { firstName: "John" lastName: "Peter" isConfirmed: true } 

I would like to highlight the statement object and the isConfirmed property on the same line using es6 destructuring

I tried

 const { statement: isConfirmed, isAdmin } = this.props 

which i get when i do let a = isConfirmed, b = statement

+22
source share
1 answer

I would like to extract the statement object and the isConfirmed property on the same line

 const { statement: { isConfirmed }, statement } = this.props; 

This way you get both isConfirmed and the entire statement object.

Literature:

+45
source

Source: https://habr.com/ru/post/1259793/


All Articles