@@ -30,7 +30,6 @@ linkClass = function (element, styles, userConfiguration) {
30
30
if ( styles === undefined ) styles = { } ;
31
31
32
32
var appendClassName = undefined ,
33
- childrenCount = undefined ,
34
33
clonedElement = undefined ,
35
34
configuration = undefined ,
36
35
newChildren = undefined ,
@@ -67,26 +66,29 @@ linkClass = function (element, styles, userConfiguration) {
67
66
appendClassName = appendClassName . join ( ' ' ) ;
68
67
}
69
68
70
- if ( _utils2 [ 'default' ] . isArray ( element . props . children ) || _react2 [ 'default' ] . isValidElement ( element . props . children ) ) {
71
- childrenCount = _react2 [ 'default' ] . Children . count ( element . props . children ) ;
69
+ // element.props.children can be one of the following:
70
+ // 'text'
71
+ // ['text']
72
+ // [ReactElement, 'text']
73
+ // ReactElement
72
74
73
- // console.log('childrenCount', childrenCount, ' element.props.children', element.props.children);
75
+ // console.log(`element.props.children`, element.props.children, `React.Children.count( element.props.children)`, React.Children.count( element.props.children) );
74
76
75
- if ( childrenCount > 1 || _utils2 [ 'default' ] . isArray ( element . props . children ) ) {
76
- newChildren = _react2 [ 'default' ] . Children . map ( element . props . children , function ( node ) {
77
- if ( _react2 [ 'default' ] . isValidElement ( node ) ) {
78
- return linkClass ( node , styles , configuration ) ;
79
- } else {
80
- return node ;
81
- }
82
- } ) ;
83
- // https://github.com/facebook/react/issues/4723#issuecomment-135555277
84
- // Forcing children into an array produces the following error:
85
- // Warning: A ReactFragment is an opaque type. Accessing any of its properties is deprecated. Pass it to one of the React.Children helpers.
86
- // newChildren = _.values(newChildren);
87
- } else if ( childrenCount === 1 ) {
88
- newChildren = linkClass ( _react2 [ 'default' ] . Children . only ( element . props . children ) , styles , configuration ) ;
77
+ if ( _react2 [ 'default' ] . isValidElement ( element . props . children ) ) {
78
+ newChildren = linkClass ( _react2 [ 'default' ] . Children . only ( element . props . children ) , styles , configuration ) ;
79
+ } else if ( _utils2 [ 'default' ] . isArray ( element . props . children ) ) {
80
+ newChildren = _react2 [ 'default' ] . Children . map ( element . props . children , function ( node ) {
81
+ if ( _react2 [ 'default' ] . isValidElement ( node ) ) {
82
+ return linkClass ( node , styles , configuration ) ;
83
+ } else {
84
+ return node ;
89
85
}
86
+ } ) ;
87
+
88
+ // https://github.com/facebook/react/issues/4723#issuecomment-135555277
89
+ // Forcing children into an array produces the following error:
90
+ // Warning: A ReactFragment is an opaque type. Accessing any of its properties is deprecated. Pass it to one of the React.Children helpers.
91
+ // newChildren = _.values(newChildren);
90
92
}
91
93
92
94
if ( appendClassName ) {
0 commit comments