File tree Expand file tree Collapse file tree 4 files changed +40
-10
lines changed Expand file tree Collapse file tree 4 files changed +40
-10
lines changed Original file line number Diff line number Diff line change 106
106
"dependencies" : {
107
107
"create-react-context" : " ^0.2.2" ,
108
108
"flat" : " ^2.0.1" ,
109
+ "hoist-non-react-statics" : " ^3.0.1" ,
109
110
"prop-types" : " ^15.6.1" ,
110
111
"reselect" : " ^3.0.1"
111
112
}
Original file line number Diff line number Diff line change 1
1
import React , { Component , type ComponentType } from 'react' ;
2
+ import hoistNonReactStatic from 'hoist-non-react-statics' ;
2
3
import { LocalizeContext , type LocalizeContextProps } from './LocalizeContext' ;
3
4
4
5
export function withLocalize < Props : { } > (
5
6
WrappedComponent : ComponentType < Props >
6
7
) : ComponentType < $Diff < Props , { ...LocalizeContextProps } >> {
7
- const LocalizedComponent = ( props : Props ) => {
8
- return (
9
- < LocalizeContext . Consumer >
10
- { context => < WrappedComponent { ...context } { ...props } /> }
11
- </ LocalizeContext . Consumer >
12
- ) ;
13
- } ;
14
-
8
+ class LocalizedComponent extends Component {
9
+ render ( ) {
10
+ return (
11
+ < LocalizeContext . Consumer >
12
+ { context => < WrappedComponent { ...context } { ...this . props } /> }
13
+ </ LocalizeContext . Consumer >
14
+ ) ;
15
+ }
16
+ }
17
+ hoistNonReactStatic ( LocalizedComponent , WrappedComponent ) ;
15
18
return LocalizedComponent ;
16
19
}
Original file line number Diff line number Diff line change @@ -23,7 +23,7 @@ const getWithLocalizeWithContext = () => {
23
23
}
24
24
}
25
25
} ) ;
26
-
26
+
27
27
return require ( 'withLocalize' ) . withLocalize ;
28
28
} ;
29
29
@@ -50,4 +50,20 @@ describe('withLocalize', () => {
50
50
const wrapper = result . dive ( ) ;
51
51
expect ( wrapper . props ( ) . name ) . toEqual ( 'Testy McTest' ) ;
52
52
} ) ;
53
- } ) ;
53
+
54
+ it ( 'should hoist any existing static functions on WrappedComponent' , ( ) => {
55
+ const withLocalize = getWithLocalizeWithContext ( ) ;
56
+ class WrapperComponent extends React . Component {
57
+ static sayHello ( ) {
58
+ return 'hello' ;
59
+ }
60
+ render ( ) {
61
+ return (
62
+ < h1 > Hello You!</ h1 >
63
+ ) ;
64
+ }
65
+ } ;
66
+ const Wrapped = withLocalize ( WrapperComponent ) ;
67
+ expect ( Wrapped . sayHello ( ) ) . toEqual ( 'hello' )
68
+ } ) ;
69
+ } ) ;
Original file line number Diff line number Diff line change @@ -2830,6 +2830,12 @@ hmac-drbg@^1.0.0:
2830
2830
minimalistic-assert "^1.0.0"
2831
2831
minimalistic-crypto-utils "^1.0.1"
2832
2832
2833
+ hoist-non-react-statics@^3.0.1 :
2834
+ version "3.0.1"
2835
+ resolved "https://registry.yarnpkg.com/hoist-non-react-statics/-/hoist-non-react-statics-3.0.1.tgz#fba3e7df0210eb9447757ca1a7cb607162f0a364"
2836
+ dependencies :
2837
+ react-is "^16.3.2"
2838
+
2833
2839
home-or-tmp@^2.0.0 :
2834
2840
version "2.0.0"
2835
2841
resolved "https://registry.yarnpkg.com/home-or-tmp/-/home-or-tmp-2.0.0.tgz#e36c3f2d2cae7d746a857e38d18d5f32a7882db8"
@@ -4981,6 +4987,10 @@ react-dom@^16.3.1:
4981
4987
object-assign "^4.1.1"
4982
4988
prop-types "^15.6.0"
4983
4989
4990
+ react-is@^16.3.2 :
4991
+ version "16.5.2"
4992
+ resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.5.2.tgz#e2a7b7c3f5d48062eb769fcb123505eb928722e3"
4993
+
4984
4994
react-is@^16.4.0 :
4985
4995
version "16.4.0"
4986
4996
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.4.0.tgz#cc9fdc855ac34d2e7d9d2eb7059bbc240d35ffcf"
You can’t perform that action at this time.
0 commit comments