Reputation: 909
I would like to make the IconButton invisible when the imagePaths is an empty array through the ternary operator. But I want to show the iconButton only if the array contains values like this: But when I use my code, I see the iconButton in any case.
how can i fix my code?
this is my code
{imagePaths &&
<IconButton iconName="cancel" onPress={onRemoveImage} />
}
console.log(imagePaths);
// [] empty array
// ["SampleFile_1619356823623.jpg"] there is value in array
Upvotes: 0
Views: 54
Reputation: 12807
You just using .length
to check array has data or not:
{imagePaths.length > 0 &&
<IconButton iconName="cancel" onPress={onRemoveImage} />
}
Upvotes: 2