Update: Solution below
I'm trying to make these icons from my data file appear, but it's showing [object object] and then undefined for the data that doesn't have any icons
Here is what I wrote that shows the errors
<div>
{dropdown ? `${item.iconClosed}` : `${item.iconOpened}`}
</div>
Basically I want the icons to only show if dropdown menu is opened or closed.
If I just do
<div>{item.iconClosed}</div>
it shows up completely fine. But when I try to add an if or else statement I can't seem to figure out the proper way to write it
Note in the data file, it's just an icon as the value
iconClosed: <RiIcons.RiArrowDownSFill />,
iconOpened: <RiIcons.RiArrowUpSFill />,
Also, I have data that does not have any icons, so how would I write the logic to only show these icons if the value exist or not?
My logic was this
if(dropdown) {
show upArrow
} else if(dropdown === false) {
show downArrow
} else {
show null
}
My issue is how would I write this as a ternary operator inside of my div?
<div>{dropdown && dataContainsDropdown ? "downArrow" : " "}</div>
The problem here is that I can't check if the dropdown is open and to show the upArrow
Updated answer that worked
<div>
{item.dropDown && dropdown
? item.iconOpened
: item.dropDown
? item.iconClosed
: null}
</div>
dropdownchanges its state?{item.dropDown ? 'upArrow' : ' '}then it will show the arrow icon for data that only contains dropdown data. But the dropdown gets triggered when I click on the main menu itemdropdown? Your question does not make that clear.