2017-05-20 2 views
0

Ich brauche drei Variablen cx, cx und weatherIcon von einem Objekt erhalten this.props.payload zur Zeit verwende ich diesen CodeDestrukturierung Zuordnung für verschachtelte Eigenschaften

const { cx, cy } = this.props 
const {weatherIcon} = this.props.payload 

Es funktioniert, aber ich würde gerne wissen, ob es möglich ist, schreibe in einer Zeile.

Antwort

2

Versuchen Sie es.

const { cx, cy, payload: { weatherIcon } } = this.props; 

const props = { cx: 1, cy: 2, payload: { weatherIcon: 3 }}; 
 
const { cx, cy, payload: { weatherIcon } } = props; 
 
console.log(cx, cy, weatherIcon);

Verwandte Themen