react-native - 错误:组件 [ComponentName] 声明了 `PropTypes` 而不是 `propTypes`。您是否拼错了属性分配?
问题描述
有人可以解释为什么我在导入 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;
解决方案
在定义 propTypes 时,您应该使用 camelCase 而不是 TitleCase。
做这个:
CustomBackground.propTypes = {...}
代替
CustomBackground.PropTypes = {...}
推荐阅读
- google-apps-script - Google 表格 ImportXML 定期刷新且不缓存
- azure - 如何使用 AzureCLI 按日期删除 Azure Blob 存储中的文件?
- c - libavcodec/libx264 不尊重 keyint_min
- octave - 在 linux 控制台中为 UTF-8 配置 Octave
- html - CSS 行距:未在元素中应用
- neo4j - Gremlin/Janusgraph 中的多个顶点标签是否可能,或者是否有更好的替代解决方案?
- arrays - 从文件中读取字符串并转换为数组 Julia
- android - 当片段返回的数据为空时,如何在视图寻呼机中动态操作片段
- amazon-web-services - 如何为每个在aws中动态登录我的网站的用户创建子域
- r - 通过 id 重塑并保持其他变量不变