React Native 错误:组件[PropTypes Name]声明了`PropTypes`而不是`propTypes`,是否拼错了属性赋值?

ukxgm1gy  于 6个月前  发布在  React
关注(0)|答案(2)|浏览(59)

有人可以解释为什么我在导入PropTypes时会出现此错误:
组件CustomBackground声明了PropTypes而不是propTypes。是否拼错了属性赋值?

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;

字符串

gev0vcfq

gev0vcfq1#

在定义propType时,应使用camelCase而不是TitleCase。
这样做:

CustomBackground.propTypes = {...}

字符串
而不是

CustomBackground.PropTypes = {...}

goucqfw6

goucqfw62#

这里是完整的代码

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

字符串

相关问题