This should be pretty simple but keep giving me error:
Here is my array:
const section = [
{
trigger: {
title: 'Data',
icon: <Icon />,
editIcon: <Edit onClick={e => console.log(e)} />,
},
component: (
<ListOne
/>
),
},
{
trigger: {
title: 'OTHER PERSONAL DATA',
icon: <Like />,
editIcon: <Edit onClick={e => this.goToOtherPersonalData(e)} />,
},
component: (
<ListTwo
}
/>
),
},
...
]
What i wanna do is display some component from the array based on a boolean prop like this:
const section = [
propIsTrue && {
trigger: {
title: 'Data',
icon: <Icon />,
editIcon: <Edit onClick={e => console.log(e)} />,
},
component: (
<ListOne
/>
),
},
{
trigger: {
title: 'OTHER PERSONAL DATA',
icon: <Like />,
editIcon: <Edit onClick={e => this.goToOtherPersonalData(e)} />,
},
component: (
<ListTwo
}
/>
),
},
...
]
But doesn't seems to be the correct syntax and give me error:
Uncaught TypeError: Cannot read properties of undefined (reading 'onClick')
So my answer is: Which is the correct way to dynamically display components based on passed prop?
Thanks in advance