let's say that I have a function that includes an object
const someFunc =props=> ({
styles:{
somedata: 'somedata:',
},
infoSectionValue: {
bold: true,
},
images:{
donut: props.donut_base64,
icon: 'some icon'
},
content: [1,2,3]
}
})`
now I want to get the icon using object destruction
`const {images :{ icon }} = someFunc()
console.log(icon)
ERROR :
props not define
it didn't work while there are other objects or props included
how can I get the icon in this case?
this is only way only have worked, if the function is to maintain the object:
const someFunc =props=> {
images:{
icon: 'some icon'
}
}
You probably mean object destructuring, not destruction.
This works (you're missing parenthesis):
Edit: There are multiple errors in your example code, this shows a couple of options: