listifyChildren function

ReactNode? listifyChildren(
  1. ReactNode? children
)

Prepares children to be passed to the ReactJS React.createElement and the Dart Component2.

Currently only involves converting a top-level non-List Iterable to a non-growable List, but this may be updated in the future to support advanced nesting and other kinds of children.

Implementation

ReactNode listifyChildren(ReactNode children) {
  if (React.isValidElement(children)) {
    // Short-circuit if we're dealing with a ReactElement to avoid the dart2js
    // interceptor lookup involved in Dart type-checking.
    return children;
  } else if (children is Iterable && children is! List) {
    return children.toList(growable: false);
  } else {
    return children;
  }
}