DEV Community

Discussion on: propTypes use in react and some ways to avoid 😫🔧 Errors

Collapse
 
nbbdog11 profile image
Scott Wagner • Edited

hey, that issue mentioned on github is actually due to the way that the proptypes are added to the component, it's not an issue with the import.

this is good:

TodoItem.propTypes = {
  // whatever proptypes
}

this is not:

TodoItem.PropTypes = {
    // whatever proptypes
}
Collapse
 
kylessg profile image
Kyle Johnson • Edited

Really nice to help people out here with the post :), but just to avoid confusion here, Scott is correct.

The article states the problem is with

import propTypes from 'prop-types';

This is not the case. the problem was simply React components expose a property propTypes, not PropTypes. For example, one could still write:

import PropTypes from 'prop-types';
...
MyComponent.propTypes ={
 mySuperProp: PropTypes.string.isRequired.
}

That part doesn't matter as you can declare whatever variable name you wish here.