I'm currently using a ternary operator to return true if reportDate.parent
exists. The problem is that it returns true but for some arrays that return there are no value
properties, so the report breaks.
{
reportData.parent && (
<React.Fragment>
<Report/>
</React.Fragment>
)
}
The below breaks:
parent: Array(3)
0: {dateTime: "05/09/2018"}
1: {dateTime: "16/06/2018"}
2: {dateTime: "19/03/2018"}
length: 3
The below works because it has at least 1 value:
parent: Array(3)
0: {dateTime: "05/09/2018", value: 2}
1: {dateTime: "16/06/2018"}
2: {dateTime: "19/03/2018"}
length: 3
I need to do the check at this top level before the report component is returned, something like:
{
reportData.parent.value === undefined && (
<React.Fragment>
<Report />
</React.Fragment>
)
}
Do I or can I use a ternary operator or another method of conditional rendering here?
To reiterate I want the report to return only if there is at least one value in the array.
Update: I am only looking to see if the key(named value) exists (not simply if a value exists inside the array)