1 | import React from 'react';
|
2 | import { isFragment } from 'react-is';
|
3 | export default function toArray(children) {
|
4 | var ret = [];
|
5 | React.Children.forEach(children, function (child) {
|
6 | if (child === undefined || child === null) {
|
7 | return;
|
8 | }
|
9 |
|
10 | if (Array.isArray(child)) {
|
11 | ret = ret.concat(toArray(child));
|
12 | } else if (isFragment(child) && child.props) {
|
13 | ret = ret.concat(toArray(child.props.children));
|
14 | } else {
|
15 | ret.push(child);
|
16 | }
|
17 | });
|
18 | return ret;
|
19 | } |
\ | No newline at end of file |