Change:
I am working on a very simple component with default props. And I simply render it without any props (). But I got an empty object from console output. I am using react 0.13.1, chrome 41, OSX 10.10. Any idea what is going wrong?
Es6 classes need defaultProps as a static property. Navigation.defaultProps = {...}
Thanks. Maybe update this in documentation :) ? I will be happy to send in a PR
has some commentary on docs and es6. I agree that I’d like to see better docs on the class syntax. I’m just a guy who happened to see your issue really quickly :)
does reference this. It might be good to also put some documentation in to make it a bit easier to find. I'm going to close this out since it's invalid but I'd love to see a PR with more docs :)
I think you should have also seen a runtime warning for this?
not really, though
Thanks, looks like an oversight. Fix incoming…

Discussion:
this.getName() || 'a component' ); warning( <ins> !inst.getDefaultProps || inst.getDefaultProps.isReactClassApproved, 'getDefaultProps was defined on %s, a plain JavaScript class. ' + 'This is only supported for classes created using React.createClass. ' + 'Use a static property to define defaultProps instead.', this.getName() || 'a component' ); warning( </ins> !inst.propTypes, 'propTypes was defined as an instance property on %s. Use a static ' + 'property to define propTypes instead.',

but does not invoke them.', -> spyOn console, 'error' getInitialStateWasCalled = false <ins> getDefaultPropsWasCalled = false </ins> class Foo extends React.Component constructor: -> @contextTypes = {}

getInitialStateWasCalled = true {} <ins> getDefaultProps: -> getDefaultPropsWasCalled = true {} </ins> render: -> span className: 'foo' test React.createElement(Foo), 'SPAN', 'foo' expect(getInitialStateWasCalled).toBe false <del> expect(console.error.calls.length).toBe 3 </del> <ins> expect(getDefaultPropsWasCalled).toBe false expect(console.error.calls.length).toBe 4 </ins> expect(console.error.calls[0].args[0]).toContain( 'getInitialState was defined on Foo, a plain JavaScript class.' ) expect(console.error.calls[1].args[0]).toContain( <del> 'propTypes was defined as an instance property on Foo.' </del> <ins> 'getDefaultProps was defined on Foo, a plain JavaScript class.' </ins> ) expect(console.error.calls[2].args[0]).toContain( <ins> 'propTypes was defined as an instance property on Foo.' ) expect(console.error.calls[3].args[0]).toContain( </ins> 'contextTypes was defined as an instance property on Foo.' )

it('warns when classic properties are defined on the instance, ' + 'but does not invoke them.', function() { spyOn(console, 'error'); <ins> var getDefaultPropsWasCalled = false; </ins> var getInitialStateWasCalled = false; class Foo extends React.Component { constructor() {

getInitialStateWasCalled = true; return {}; } <ins> getDefaultProps() { getDefaultPropsWasCalled = true; return {}; } </ins> render() { return <span className="foo" />; } } test(<Foo />, 'SPAN', 'foo'); expect(getInitialStateWasCalled).toBe(false); <del> expect(console.error.calls.length).toBe(3); </del> <ins> expect(getDefaultPropsWasCalled).toBe(false); expect(console.error.calls.length).toBe(4); </ins> expect(console.error.calls[0].args[0]).toContain( 'getInitialState was defined on Foo, a plain JavaScript class.' ); expect(console.error.calls[1].args[0]).toContain( <del> 'propTypes was defined as an instance property on Foo.' </del> <ins> 'getDefaultProps was defined on Foo, a plain JavaScript class.' </ins> ); expect(console.error.calls[2].args[0]).toContain( <ins> 'propTypes was defined as an instance property on Foo.' ); expect(console.error.calls[3].args[0]).toContain( </ins> 'contextTypes was defined as an instance property on Foo.' ); });

// warns when classic properties are defined on the instance, // but does not invoke them. var getInitialStateWasCalled = false; <ins> var getDefaultPropsWasCalled = false; </ins> class ClassicProperties extends React.Component { contextTypes = {}; propTypes = {}; <ins> getDefaultProps() { getDefaultPropsWasCalled = true; return {}; } </ins> getInitialState() { getInitialStateWasCalled = true; return {};

var warn = jest.genMockFn(); console.error = warn; getInitialStateWasCalled = false; <ins> getDefaultPropsWasCalled = false; </ins> test(React.createElement(ClassicProperties), 'SPAN', 'foo'); expect(getInitialStateWasCalled).toBe(false); <del> expect(warn.mock.calls.length).toBe(3); </del> <ins> expect(getDefaultPropsWasCalled).toBe(false); expect(warn.mock.calls.length).toBe(4); </ins> expect(warn.mock.calls[0][0]).toContain( 'getInitialState was defined on ClassicProperties, ' + 'a plain JavaScript class.' ); expect(warn.mock.calls[1][0]).toContain( <del> 'propTypes was defined as an instance property on ClassicProperties.' </del> <ins> 'getDefaultProps was defined on ClassicProperties, ' + 'a plain JavaScript class.' </ins> ); expect(warn.mock.calls[2][0]).toContain( <ins> 'propTypes was defined as an instance property on ClassicProperties.' ); expect(warn.mock.calls[3][0]).toContain( </ins> 'contextTypes was defined as an instance property on ClassicProperties.' ); });