react-native - 错误 : Component [ComponentName] declared `PropTypes` instead of `propTypes` . 您是否拼错了属性分配?

标签 react-native react-props react-proptypes prop

有人可以解释为什么我在导入 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;

最佳答案

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

这样做:

CustomBackground.propTypes = {...}

而不是

CustomBackground.PropTypes = {...}

关于react-native - 错误 : Component [ComponentName] declared `PropTypes` instead of `propTypes` . 您是否拼错了属性分配?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67112114/

相关文章:

react-native - 为什么我无法在我的 android 设备上运行 react-native 应用程序?

javascript - 如何将 Python OpenCV 与 React Native 集成

ios - 将 react-native-router-flux 与 redux 一起使用,如何更新 View 组件中的状态?

ios - 自定义卡片 View 的 Flatlist/SectionList 的实现

javascript - 使用 ESLint react PropType

javascript - React如何修复失败的 Prop 类型 - 字符串类型预期对象的无效 Prop

javascript - 通过只传递一次 props 来多次执行状态和数组操作

javascript - 使用 this.state 在渲染中设置状态

javascript - 当通过子组件更改父状态时,React 重新渲染

reactjs - prop 类型在 React 应用程序中不起作用