Skip to content
This repository was archived by the owner on Dec 16, 2021. It is now read-only.

Commit 1f0e508

Browse files
joeyrobertdevelopit
authored andcommitted
Call getDefaultProps on the class so statics can be read (#421)
1 parent 5ca5748 commit 1f0e508

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ function createClass(obj) {
424424
cl.defaultProps = obj.defaultProps;
425425
}
426426
if (obj.getDefaultProps) {
427-
cl.defaultProps = obj.getDefaultProps();
427+
cl.defaultProps = obj.getDefaultProps.call(cl);
428428
}
429429

430430
F.prototype = Component.prototype;

test/component.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,25 @@ describe('components', () => {
292292
});
293293
});
294294

295+
it('should work with statics', () => {
296+
const Foo = React.createClass({
297+
statics: {
298+
a: false
299+
},
300+
getDefaultProps() {
301+
return { b: true, c: this.a };
302+
},
303+
render() {
304+
return <div />;
305+
}
306+
});
307+
308+
expect(Foo.defaultProps).to.eql({
309+
b: true,
310+
c: false
311+
});
312+
});
313+
295314
// Disabled to save bytes
296315
xit('should throw an error for duplicate keys', () => {
297316
expect(() => {

0 commit comments

Comments
 (0)