File tree Expand file tree Collapse file tree 2 files changed +12
-9
lines changed Expand file tree Collapse file tree 2 files changed +12
-9
lines changed Original file line number Diff line number Diff line change @@ -64,7 +64,7 @@ describe('withRouter', function () {
64
64
} )
65
65
66
66
it ( 'should support withRefs as a parameter' , function ( done ) {
67
- const WrappedApp = withRouter ( App , { withRef :true } )
67
+ const WrappedApp = withRouter ( App , { withRef : true } )
68
68
const router = {
69
69
push ( ) { } ,
70
70
replace ( ) { } ,
Original file line number Diff line number Diff line change @@ -9,20 +9,23 @@ function getDisplayName(WrappedComponent) {
9
9
}
10
10
11
11
export default function withRouter ( WrappedComponent , options ) {
12
+ const { withRef } = options || { }
13
+
12
14
const WithRouter = React . createClass ( {
13
15
contextTypes : { router : routerShape } ,
14
16
propTypes : { router : routerShape } ,
17
+
15
18
getWrappedInstance ( ) {
16
- warning ( options && options . withRef , 'To access the wrappedInstance you must provide {withRef : true} as the second argument of the withRouter call' )
17
- return this . _wrappedComponent
19
+ warning ( withRef , 'To access the wrappedInstance you must provide { withRef : true } as the second argument of the withRouter call' )
20
+ return this . wrappedComponent
18
21
} ,
22
+
19
23
render ( ) {
20
- const router = this . props . router || this . context . router
21
- if ( options && options . withRef ) {
22
- return < WrappedComponent { ...this . props } ref = { ( component ) => this . _wrappedComponent = component } router = { router } />
23
- } else {
24
- return < WrappedComponent { ...this . props } router = { router } />
25
- }
24
+ const { router, ...props } = this . props
25
+
26
+ if ( withRef ) props . ref = component => this . wrappedComponent = component
27
+
28
+ return < WrappedComponent { ...props } router = { router || this . context . router } />
26
29
}
27
30
} )
28
31
You can’t perform that action at this time.
0 commit comments