如果给定一个实例,我可以检查反应组件 class 的 proptypes 吗?

Can I inspect the proptypes of react component class if given an instance?

我想访问 class 的 propTypes,例如

var Button = React.createClass({
  propTypes: {
    text: React.PropTypes.string,
    href: React.PropTypes.string
  },
  ...
})

...

var ButtonPropTypes = Button.propTypes

我希望看到类似

的内容
{ text: function(){...}, href: function(){...} }

但我得到的是 undefined。我做错了什么,我怎样才能得到 proptypes?

您应该能够像在代码中一样静态访问 proptypes。我在 jsfiddle 上举了一个例子,你应该能够看到在控制台中打印的 proptypes(它们是函数)

var Hello = React.createClass({
    getDefaultProps: function() {
        return {
          testing: 'default value'
        };
    },
    propTypes: {
        testing: React.PropTypes.string
    },
    render: function() {
        return (
            <div>        
                <div>{this.props.name}</div>
            </div>
        )
    }
});

React.render(<Hello name="World" />, document.getElementById('container'));

console.log(Hello.propTypes)

https://jsfiddle.net/fj7ax0qr/