static propTypes Vs React.PropTypes

This is an es7 version

class App extends React.Component {
  static propTypes = {
    ...
  }
}

while this is the es6 version

class App extends React.Component {
  ...
}

App.propTypes = {
  ...
}

Personally I prefer the es7 version because it makes more sense to view the propTypes at the top of the component, to give an overview of what is needed to render the component (similar to what parameters are needed for a function).

Regardless of which version you are using, if you want to strip propTypes for production, you need to use https://github.com/oliviertassinari/babel-plugin-transform-react-remove-prop-types. Alternatively, you can use https://github.com/thejameskyle/babel-react-optimize which includes the above transform plus a few other goodies since I guess you would also want to optimize your app further (:

Leave a Comment