Skip to content

Commit 2f7ec22

Browse files
committed
Merge pull request #127 from erikras/master
Allow connect() to hoist non-react statics from wrapped component
2 parents 5c5f388 + 5d7d448 commit 2f7ec22

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
"webpack": "^1.11.0"
5959
},
6060
"dependencies": {
61+
"hoist-non-react-statics": "^1.0.3",
6162
"invariant": "^2.0.0"
6263
},
6364
"peerDependencies": {

src/components/createConnect.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import createStoreShape from '../utils/createStoreShape';
22
import shallowEqual from '../utils/shallowEqual';
33
import isPlainObject from '../utils/isPlainObject';
44
import wrapActionCreators from '../utils/wrapActionCreators';
5+
import hoistStatics from 'hoist-non-react-statics';
56
import invariant from 'invariant';
67

78
const defaultMapStateToProps = () => ({});
@@ -232,7 +233,7 @@ export default function createConnect(React) {
232233
};
233234
}
234235

235-
return Connect;
236+
return hoistStatics(Connect, WrappedComponent);
236237
};
237238
};
238239
}

test/components/connect.spec.js

+18
Original file line numberDiff line numberDiff line change
@@ -1021,6 +1021,24 @@ describe('React', () => {
10211021
expect(decorated.WrappedComponent).toBe(Container);
10221022
});
10231023

1024+
it('should hoist non-react statics from wrapped component', () => {
1025+
class Container extends Component {
1026+
static howIsRedux = () => 'Awesome!';
1027+
static foo = 'bar';
1028+
1029+
render() {
1030+
return <Passthrough />;
1031+
}
1032+
}
1033+
1034+
const decorator = connect(state => state);
1035+
const decorated = decorator(Container);
1036+
1037+
expect(decorated.howIsRedux).toBeA('function');
1038+
expect(decorated.howIsRedux()).toBe('Awesome!');
1039+
expect(decorated.foo).toBe('bar');
1040+
});
1041+
10241042
it('should use the store from the props instead of from the context if present', () => {
10251043
class Container extends Component {
10261044
render() {

0 commit comments

Comments
 (0)