错误:组件 [ComponentName] 声明了 `PropTypes` 而不是 `propTypes`。您是否拼错了属性分配?

问题描述 投票:0回答:2

有人可以解释为什么我在导入 PropTypes 时收到此错误:

组件 CustomBackground 声明为

PropTypes
而不是
propTypes
。您是否拼错了属性分配?

自定义背景.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;
react-native react-props react-proptypes prop
2个回答
4
投票

定义 propTypes 时应使用驼峰命名法而不是 TitleCase。

这样做:

CustomBackground.propTypes = {...}

而不是

CustomBackground.PropTypes = {...}

0
投票

这是完整代码

CustomBackground.propTypes={
    children:PropTypes.element.isRequired,
}
© www.soinside.com 2019 - 2024. All rights reserved.