So I have a list of Items
const items = this.props.complex_object?.items;
And I would like to sort these items based on a key. I would naturally like to perform the following
const sortedItems = this.props.complex_object?.items.sort(
(a, b) => a?.confidence > b?.confidence
);
Yet I am getting the following flow error.
Flow does not yet support method or property calls in optional chains.
Which somewhat makes sense because items
is of the flow type ?Array<ItemType>
. Given the conditional nature of the existence of Items
, I have tried to check for null and undefined
var items = this.props.complex_object?.items;
if (items === null || items === undefined)
items = [];
const sortedItems = items.sort((a, b) => a. confidence > b.confidence);
return (<Table items=sortedItems>);
Yet this doesn't alleviate the problem. Bottom line, how do I sort an array of optional objects?
Many Thanks in Advance