Skip to content

Commit 510b8d4

Browse files
committed
Merge pull request gajus#47 from lukewestby/master
hoist static properties of stateless functions
2 parents 1fadab5 + c84d5ab commit 510b8d4

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/wrapStatelessFunction.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ let wrapStatelessFunction;
1212
* @returns {function}
1313
*/
1414
wrapStatelessFunction = (Component, defaultStyles, options) => {
15-
return (props = {}, ...args) => {
15+
let WrappedComponent;
16+
17+
WrappedComponent = (props = {}, ...args) => {
1618
let renderResult,
1719
styles,
1820
useProps;
@@ -39,6 +41,10 @@ wrapStatelessFunction = (Component, defaultStyles, options) => {
3941

4042
return React.createElement('noscript');
4143
};
44+
45+
_.assign(WrappedComponent, Component);
46+
47+
return WrappedComponent;
4248
};
4349

4450
export default wrapStatelessFunction;

test/wrapStatelessFunction.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,23 @@ import {
77
import wrapStatelessFunction from './../src/wrapStatelessFunction';
88

99
describe('wrapStatelessFunction', () => {
10+
it('hoists static own properties from the input component to the wrapped component', () => {
11+
let Component, WrappedComponent, styles;
12+
13+
styles = {
14+
foo: 'foo-1'
15+
};
16+
17+
Component = function InnerComponent () { return null; };
18+
Component.propTypes = {};
19+
Component.defaultProps = {};
20+
21+
WrappedComponent = wrapStatelessFunction(Component, styles);
22+
23+
expect(WrappedComponent.propTypes).to.equal(Component.propTypes);
24+
expect(WrappedComponent.defaultProps).to.equal(Component.defaultProps);
25+
expect(WrappedComponent.name).not.to.equal(Component.name);
26+
});
1027
context('using default styles', () => {
1128
it('exposes styles through styles property', (done) => {
1229
let styles;

0 commit comments

Comments
 (0)