Skip to content

Commit

Permalink
refactor(Transition): simplify render function (#621)
Browse files Browse the repository at this point in the history
  • Loading branch information
iamandrewluca authored May 6, 2020
1 parent 6ab4473 commit 46bdb6e
Showing 1 changed file with 24 additions and 28 deletions.
52 changes: 24 additions & 28 deletions src/Transition.js
Original file line number Diff line number Diff line change
Expand Up @@ -341,42 +341,38 @@ class Transition extends React.Component {

render() {
const status = this.state.status

if (status === UNMOUNTED) {
return null
}

const { children, ...childProps } = this.props
// filter props for Transtition
delete childProps.in
delete childProps.mountOnEnter
delete childProps.unmountOnExit
delete childProps.appear
delete childProps.enter
delete childProps.exit
delete childProps.timeout
delete childProps.addEndListener
delete childProps.onEnter
delete childProps.onEntering
delete childProps.onEntered
delete childProps.onExit
delete childProps.onExiting
delete childProps.onExited
delete childProps.nodeRef

if (typeof children === 'function') {
// allows for nested Transitions
return (
<TransitionGroupContext.Provider value={null}>
{children(status, childProps)}
</TransitionGroupContext.Provider>
)
}
const {
children,
// filter props for `Transition`
in: _in,
mountOnEnter: _mountOnEnter,
unmountOnExit: _unmountOnExit,
appear: _appear,
enter: _enter,
exit: _exit,
timeout: _timeout,
addEndListener: _addEndListener,
onEnter: _onEnter,
onEntering: _onEntering,
onEntered: _onEntered,
onExit: _onExit,
onExiting: _onExiting,
onExited: _onExited,
nodeRef: _nodeRef,
...childProps
} = this.props

const child = React.Children.only(children)
return (
// allows for nested Transitions
<TransitionGroupContext.Provider value={null}>
{React.cloneElement(child, childProps)}
{typeof children === 'function'
? children(status, childProps)
: React.cloneElement(React.Children.only(children), childProps)}
</TransitionGroupContext.Provider>
)
}
Expand Down

0 comments on commit 46bdb6e

Please sign in to comment.