Skip to content

Commit

Permalink
fix: toArray logic adjust for flatten array
Browse files Browse the repository at this point in the history
  • Loading branch information
zombieJ committed Mar 9, 2020
1 parent cec7bb9 commit a63f8a5
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/Children/toArray.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@ export default function toArray(
let ret: React.ReactElement[] = [];

React.Children.forEach(children, (child: any) => {
if (isFragment(child) && child.props) {
if (child === undefined || child === null) {
return;
}

if (Array.isArray(child)) {
ret = ret.concat(toArray(child));
} else if (isFragment(child) && child.props) {
ret = ret.concat(toArray(child.props.children));
} else {
ret.push(child);
Expand Down

0 comments on commit a63f8a5

Please sign in to comment.