Это не единственный способ добавить свойства propTypes и defaultProps в класс. Ты можешь сделать:
class SomeComponent extends React.Component { static propTypes = { ... } static defaultProps = { ... } static contextTypes = { ... } render() { return <h1>Stuff</h1>} } // Or you can also declare constants const propTypes = { ... } const defaultProps = { ... } class OtherComponent extends React.Component{ ... } //Then attach at after the component definition. OtherComponent.propTypes = propTypes; OtherComponent.defaultProps = defaultProps;
Просто чтобы прояснить, мне также не нравится синтаксис class
для создания компонентов реакции. Но самодокументируемая разница между createClass и class не так уж велика.