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