diff --git a/package.json b/package.json index 1f000bf13..e75ac23b6 100644 --- a/package.json +++ b/package.json @@ -58,6 +58,7 @@ "webpack": "^1.11.0" }, "dependencies": { + "hoist-non-react-statics": "^1.0.3", "invariant": "^2.0.0" }, "peerDependencies": { diff --git a/src/components/createConnect.js b/src/components/createConnect.js index 083cd9ba0..fc0be32e0 100644 --- a/src/components/createConnect.js +++ b/src/components/createConnect.js @@ -2,6 +2,7 @@ import createStoreShape from '../utils/createStoreShape'; import shallowEqual from '../utils/shallowEqual'; import isPlainObject from '../utils/isPlainObject'; import wrapActionCreators from '../utils/wrapActionCreators'; +import hoistStatics from 'hoist-non-react-statics'; import invariant from 'invariant'; const defaultMapStateToProps = () => ({}); @@ -232,7 +233,7 @@ export default function createConnect(React) { }; } - return Connect; + return hoistStatics(Connect, WrappedComponent); }; }; } diff --git a/test/components/connect.spec.js b/test/components/connect.spec.js index 5deb23ab4..25f6eb8a9 100644 --- a/test/components/connect.spec.js +++ b/test/components/connect.spec.js @@ -1021,6 +1021,24 @@ describe('React', () => { expect(decorated.WrappedComponent).toBe(Container); }); + it('should hoist non-react statics from wrapped component', () => { + class Container extends Component { + static howIsRedux = () => 'Awesome!'; + static foo = 'bar'; + + render() { + return ; + } + } + + const decorator = connect(state => state); + const decorated = decorator(Container); + + expect(decorated.howIsRedux).toBeA('function'); + expect(decorated.howIsRedux()).toBe('Awesome!'); + expect(decorated.foo).toBe('bar'); + }); + it('should use the store from the props instead of from the context if present', () => { class Container extends Component { render() {