Skip to content

Commit

Permalink
Merge pull request #7 from Morhaus/hoc-preserve-statics
Browse files Browse the repository at this point in the history
HOC preserves non-react statics
  • Loading branch information
zallek committed Oct 29, 2015
2 parents 73f37c7 + 5b8dd44 commit 99b0dfb
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
15 changes: 15 additions & 0 deletions src/__tests__/hoc-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,19 @@ describe('classMap', () => {

});

it('preserves non react statics', () => {

@classMap({})
class Test extends React.Component {
static foo = 'bar';

render() {
return <div />;
}
}

expect(Test.foo).toBe('bar');

});

});
7 changes: 5 additions & 2 deletions src/hoc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { PropTypes } from 'react';
import hoistNonReactStatics from 'hoist-non-react-statics';

import { CLASSMAP_KEY } from './constants';
import './inject';
Expand All @@ -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() {
Expand All @@ -23,5 +24,7 @@ export default function classMap(...args) {
render() {
return <Composed {...this.props} />;
}
};
}

return hoistNonReactStatics(ClassMap, Composed);
}

0 comments on commit 99b0dfb

Please sign in to comment.