UNPKG

@fruits-chain/react-native-xiaoshu

Version:
31 lines (29 loc) 959 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = childrenToArray; var _react = require("react"); var _reactIs = require("react-is"); /** * 把 JSX 的 children 中空节点过滤,返回一个数组格式的 JSX 节点集合 * @description https://github.com/react-component/util/blob/master/src/Children/toArray.ts */ function childrenToArray(children, option = {}) { let ret = []; // eslint-disable-next-line @typescript-eslint/no-explicit-any _react.Children.forEach(children, child => { if ((child === undefined || child === null) && !option.keepEmpty) { return; } if (Array.isArray(child)) { ret = ret.concat(childrenToArray(child)); } else if ((0, _reactIs.isFragment)(child) && child.props) { ret = ret.concat(childrenToArray(child.props.children, option)); } else { ret.push(child); } }); return ret; } //# sourceMappingURL=to-array.js.map