diff --git a/package.json b/package.json index 1b7fee1..3202752 100644 --- a/package.json +++ b/package.json @@ -30,5 +30,8 @@ "react": "^0.14.0", "react-addons-test-utils": "^0.14.0", "react-dom": "^0.14.0" + }, + "dependencies": { + "hoist-non-react-statics": "^1.0.3" } } diff --git a/src/__tests__/hoc-test.js b/src/__tests__/hoc-test.js index c0ccee6..f94504c 100644 --- a/src/__tests__/hoc-test.js +++ b/src/__tests__/hoc-test.js @@ -38,4 +38,19 @@ describe('classMap', () => { }); + it('preserves non react statics', () => { + + @classMap({}) + class Test extends React.Component { + static foo = 'bar'; + + render() { + return
; + } + } + + expect(Test.foo).toBe('bar'); + + }); + }); diff --git a/src/hoc.js b/src/hoc.js index b8420a8..f643e29 100644 --- a/src/hoc.js +++ b/src/hoc.js @@ -1,4 +1,5 @@ import React, { PropTypes } from 'react'; +import hoistNonReactStatics from 'hoist-non-react-statics'; import { CLASSMAP_KEY } from './constants'; import './inject'; @@ -13,7 +14,7 @@ export default function classMap(...args) { let [Composed, map] = args; - return class ClassMap extends React.Component { + class ClassMap extends React.Component { static childContextTypes = { [CLASSMAP_KEY]: PropTypes.object }; getChildContext() { @@ -23,5 +24,7 @@ export default function classMap(...args) { render() { return ; } - }; + } + + return hoistNonReactStatics(ClassMap, Composed); }