reactjs - PropTypes 没有显示任何无效类型的警告 - React
问题描述
我是第一次实现 PropTypes,但它没有按预期验证道具。当存在不匹配的数据类型或没有传递数据时没有警告,并且只显示文本。以下是组件的代码:
组件:
class Counter extends React.Component {
constructor() {
super();
this.state = {
count: 0
};
}
/** some other code **/
render() {
return (
<View style={styles.appContainer}>
<Text style={styles.count}>{this.state.count}</ Text>
<Text>{this.props.num}</Text>
</View>
);
}
}
Counter.propTypes = {
num: PropTypes.number.isRequired
}
这是使用该组件的地方:
<View style={styles.appContainer}>
<Button title="toggle" onPress={this.toggleCounter}/>
<Counter num={"hi"}/>
</View>
解决方案
推荐阅读
- java - out of order processing of a Flux of input using Reactor
- ios - Swift 崩溃 Crashlytics 0x0000000104fbdf84
- python - How to rearrange separate dataframes and join them into a single summary dataframe?
- python - 用 4 个字节将数字转换为二进制?
- flutter - Flutter 找不到具有权限的提供者的元数据
- c# - 当前上下文中不存在名称 frm
- html - Google Apps Script not picking up HTML formatting in template
- android - 如何让杰克逊不将 1 或“真”解析为布尔值?
- angular - 如何从角度html中的数组中过滤对象属性
- html - React App中的焦点DOM元素在useEffect问题中