React Native propTypes 不起作用

React Native propTypes not working

我正在尝试将 propTypes 用于我的 RN 申请,但它似乎从未被强制执行。我的组件看起来像这样:

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 文件

"plugins": [
  "transform-class-properties",
]

我试过制作必需的道具

static propTypes = {
  data: React.PropTypes.string.isRequired,
};

我什至尝试将 export class Table... 更改为 export default class Table...,但没有成功。我已经尝试了上面列出的方法的所有组合,但都无济于事。我错过了什么?

当我摆弄代码时,问题似乎自行消失了。这可能是一个环境问题,就像@asaf david 建议的那样,我不太确定。我试着回去把东西改回去看看我是否可以重现,但我不能:(。我很抱歉以后搜索这个的人。