我想为我的RN应用程序使用propTypes
,但它似乎从未被强制执行。我的组件看起来是这样的:反应原生propTypes不起作用
import React, { Component } from "react";
import { Text } form "react-native";
export class Table extends Component {
render() {
return (<Text>...</Text>);
}
}
Table.propTypes = {
data: React.PropTypes.string,
};
这没提醒我通过一个数字组件这样从另一个文件:
<Table data= { 2000 } />
所以我试图使propTypes
的Table
因为静态属性我看到了有关ES6一些东西与propTypes工作这种方式:
import React, { Component } from "react";
import { Text } form "react-native";
export class Table extends Component {
static propTypes = {
data: React.PropTypes.string,
};
render() {
return (<Text>...</Text>);
}
}
然后我尝试添加一个插件来我.babelrc
FIL Ë
"plugins": [
"transform-class-properties",
]
我试着制作道具需要
static propTypes = {
data: React.PropTypes.string.isRequired,
};
我甚至已经试过,没有运气改变export class Table...
到export default class Table...
。我已经尝试了上面列出的方法的每个组合都无济于事。我错过了什么?
我不知道你是否知道这个,但你应该使用“等号”字符传递一个道具
这是我的文章中的一个错误,我的实际代码使用'=' ,我已经在我的帖子中修复了它 – mithunm93
React proptypes只能在开发环境中工作,所以请确认你没有在生产env –