File tree Expand file tree Collapse file tree 2 files changed +33
-1
lines changed Expand file tree Collapse file tree 2 files changed +33
-1
lines changed Original file line number Diff line number Diff line change 1- import toChildrenArray from 'rc-util/es/Children/toArray' ;
21import warning from 'rc-util/es/warning' ;
32import * as React from 'react' ;
3+ import toChildrenArray from './utils/toChildrenArray' ;
44import type {
55 FieldEntity ,
66 FormInstance ,
Original file line number Diff line number Diff line change 1+ import React , { ReactNode } from 'react' ;
2+
3+ interface ToArrayOptions {
4+ keepEmpty ?: boolean ;
5+ }
6+
7+ export default function toChildrenArray (
8+ children : ReactNode ,
9+ option : ToArrayOptions = { } ,
10+ ) : ReactNode [ ] {
11+ let ret : ReactNode [ ] = [ ] ;
12+
13+ if ( ! option . keepEmpty ) {
14+ children = React . Children . toArray ( children ) . filter (
15+ child => child !== undefined && child !== null ,
16+ ) ;
17+ } else {
18+ children = React . Children . toArray ( children ) ;
19+ }
20+
21+ ret = ( children as ReactNode [ ] ) . flatMap ( child => {
22+ if ( Array . isArray ( child ) ) {
23+ return toChildrenArray ( child , option ) ;
24+ } else if ( React . isValidElement ( child ) && child . type === React . Fragment && child . props ) {
25+ return toChildrenArray ( child . props . children , option ) ;
26+ } else {
27+ return child ;
28+ }
29+ } ) ;
30+
31+ return ret ;
32+ }
You can’t perform that action at this time.
0 commit comments