Skip to content

Commit e33ffd3

Browse files
committed
Hoist statics.
1 parent 9fae263 commit e33ffd3

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
},
2121
"license": "BSD-3-Clause",
2222
"dependencies": {
23+
"hoist-non-react-statics": "^1.0.3",
2324
"lodash": "^4.0.0"
2425
},
2526
"devDependencies": {

src/extendReactClass.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import linkClass from './linkClass';
44
import React from 'react';
55
import _ from 'lodash';
6+
import hoistNonReactStatics from 'hoist-non-react-statics';
67

78
let extendReactClass;
89

@@ -13,7 +14,9 @@ let extendReactClass;
1314
* @returns {ReactClass}
1415
*/
1516
extendReactClass = (Component, defaultStyles, options) => {
16-
return class extends Component {
17+
let WrappedComponent;
18+
19+
WrappedComponent = class extends Component {
1720
render () {
1821
let renderResult,
1922
styles;
@@ -39,6 +42,8 @@ extendReactClass = (Component, defaultStyles, options) => {
3942
return React.createElement('noscript');
4043
}
4144
};
45+
46+
return hoistNonReactStatics(WrappedComponent, Component);
4247
};
4348

4449
export default extendReactClass;

tests/extendReactClass.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,23 @@ describe('extendReactClass', () => {
102102
expect(component.type).to.equal('noscript');
103103
});
104104
});
105+
context('target component have static properties', () => {
106+
it('hoists static properties', () => {
107+
let Component,
108+
WrappedComponent;
109+
110+
Component = class extends React.Component {
111+
static foo = 'FOO';
112+
113+
render () {
114+
return null;
115+
}
116+
};
117+
118+
WrappedComponent = extendReactClass(Component);
119+
120+
expect(Component.foo).to.equal('FOO');
121+
expect(WrappedComponent.foo).to.equal(Component.foo);
122+
});
123+
});
105124
});

0 commit comments

Comments
 (0)