Skip to content

Commit 6b3938e

Browse files
committed
Support multiple children provided all but one child renders null.
1 parent f8b0a29 commit 6b3938e

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/ReactCSSTransitionReplace.jsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,16 @@ const reactCSSTransitionGroupChild = React.createFactory(ReactCSSTransitionGroup
1919
const TICK = 17
2020

2121

22+
// Filter out nulls before looking for an only child
23+
function getChildMapping(children) {
24+
if (!Array.isArray(children)) {
25+
return children
26+
}
27+
const childArray = React.Children.toArray(children).filter(c => c)
28+
return childArray.length === 1 ? childArray[0] : React.Children.only(childArray)
29+
}
30+
31+
2232
export default class ReactCSSTransitionReplace extends React.Component {
2333

2434
static displayName = 'ReactCSSTransitionReplace'
@@ -53,7 +63,7 @@ export default class ReactCSSTransitionReplace extends React.Component {
5363

5464
this.state = {
5565
currentKey: '1',
56-
currentChild: this.props.children ? React.Children.only(this.props.children) : undefined,
66+
currentChild: getChildMapping(this.props.children),
5767
prevChildren: {},
5868
height: null,
5969
}
@@ -76,7 +86,7 @@ export default class ReactCSSTransitionReplace extends React.Component {
7686
}
7787

7888
componentWillReceiveProps(nextProps) {
79-
const nextChild = nextProps.children ? React.Children.only(nextProps.children) : null
89+
const nextChild = getChildMapping(nextProps.children)
8090
const {currentChild} = this.state
8191

8292
if ((!currentChild && !nextChild) || (currentChild && nextChild && currentChild.key === nextChild.key)) {

0 commit comments

Comments
 (0)