Search code examples
react-nativereact-propsreact-proptypesprop

Error : Component [ComponentName] declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?


Someone can explain why I get this error when I import PropTypes :

Component CustomBackground declared PropTypes instead of propTypes. Did you misspell the property assignment?

CustomBackground.js :

import PropTypes from 'prop-types';


const CustomBackground=({children})=>(
    <ImageBackground source={background} style={styles.imagebackground}>
        {children}
    </ImageBackground>
)

CustomBackground.PropTypes={
    children:PropTypes.element.isRequired,
}

export default CustomBackground;

Solution

  • You should use camelCase instead of TitleCase when defining propTypes.

    Do this:

    CustomBackground.propTypes = {...}
    

    instead of

    CustomBackground.PropTypes = {...}