@@ -4,6 +4,7 @@ import ReactDOM from 'react-dom'
4
4
import { polyfill } from 'react-lifecycles-compat'
5
5
6
6
import { timeoutsShape } from './utils/PropTypes'
7
+ import TransitionGroupContext from './TransitionGroupContext'
7
8
8
9
export const UNMOUNTED = 'unmounted'
9
10
export const EXITED = 'exited'
@@ -107,17 +108,12 @@ export const EXITING = 'exiting'
107
108
* > `CSSTransition`.
108
109
*/
109
110
class Transition extends React . Component {
110
- static contextTypes = {
111
- transitionGroup : PropTypes . object ,
112
- }
113
- static childContextTypes = {
114
- transitionGroup : ( ) => { } ,
115
- }
111
+ static contextType = TransitionGroupContext
116
112
117
113
constructor ( props , context ) {
118
114
super ( props , context )
119
115
120
- let parentGroup = context . transitionGroup
116
+ let parentGroup = context
121
117
// In the context of a TransitionGroup all enters are really appears
122
118
let appear =
123
119
parentGroup && ! parentGroup . isMounting ? props . enter : props . appear
@@ -146,10 +142,6 @@ class Transition extends React.Component {
146
142
this . nextCallback = null
147
143
}
148
144
149
- getChildContext ( ) {
150
- return { transitionGroup : null } // allows for nested Transitions
151
- }
152
-
153
145
static getDerivedStateFromProps ( { in : nextIn } , prevState ) {
154
146
if ( nextIn && prevState . status === UNMOUNTED ) {
155
147
return { status : EXITED }
@@ -236,8 +228,8 @@ class Transition extends React.Component {
236
228
237
229
performEnter ( node , mounting ) {
238
230
const { enter } = this . props
239
- const appearing = this . context . transitionGroup
240
- ? this . context . transitionGroup . isMounting
231
+ const appearing = this . context
232
+ ? this . context . isMounting
241
233
: mounting
242
234
243
235
const timeouts = this . getTimeouts ( )
@@ -364,11 +356,21 @@ class Transition extends React.Component {
364
356
delete childProps . onExited
365
357
366
358
if ( typeof children === 'function' ) {
367
- return children ( status , childProps )
359
+ // allows for nested Transitions
360
+ return (
361
+ < TransitionGroupContext . Provider value = { null } >
362
+ { children ( status , childProps ) }
363
+ </ TransitionGroupContext . Provider >
364
+ )
368
365
}
369
366
370
367
const child = React . Children . only ( children )
371
- return React . cloneElement ( child , childProps )
368
+ return (
369
+ // allows for nested Transitions
370
+ < TransitionGroupContext . Provider value = { null } >
371
+ { React . cloneElement ( child , childProps ) }
372
+ </ TransitionGroupContext . Provider >
373
+ )
372
374
}
373
375
}
374
376
0 commit comments