React-Native 16 Alpha 12 迁移 PropTypes

React-Native 16 Alpha 12 Migrating PropTypes

我的 Expo XDE 在新创建的项目上给我以下警告:

1:37:35 PM Warning: checkPropTypes has been moved to a separate package. Accessing React.checkPropTypes is no longer supported and will be removed completely in React 16. Use the prop-types package on npm instead.

1:37:35 PM Warning: React.createClass is no longer supported. Use a plain JavaScript class instead. If you're not yet ready to migrate, create-react-class is available on npm as a drop-in replacement.

1:37:35 PM Warning: PropTypes has been moved to a separate package. Accessing React.PropTypes is no longer supported and will be removed completely in React 16. Use the prop-types package on npm instead.

Migrating Prop-Types

即使我的代码看起来没问题..有谁知道为什么我仍然收到这条消息或者下面的代码有什么问题?

代码

import React, {Component} from 'react';
import Root from './src/Root';
import {View} from 'react-native';
import PropTypes from 'prop-types';

class App extends Component {
  render() {
    return (<View />);
  }
}

App.PropTypes = {}

export default App;

package.json

{
  "name": "WeDo",
  "version": "0.1.0",
  "private": true,
  "devDependencies": {
    "react-native-scripts": "1.2.1",
    "jest-expo": "~20.0.0",
    "react-test-renderer": "16.0.0-alpha.12"
  },
  "main": "./node_modules/react-native-scripts/build/bin/crna-entry.js",
  "scripts": {
    "start": "react-native-scripts start",
    "eject": "react-native-scripts eject",
    "android": "react-native-scripts android",
    "ios": "react-native-scripts ios",
    "test": "node node_modules/jest/bin/jest.js --watch"
  },
  "jest": {
    "preset": "jest-expo"
  },
  "dependencies": {
    "expo": "^20.0.0",
    "prop-types": "^15.5.10",
    "react": "16.0.0-alpha.12",
    "react-native": "^0.47.0"
  }
}

App 上的 属性 应该是 propTypes 而不是 PropTypes。但是,您仍然在对象中使用 PropTypes

例如:

App.propTypes = {
  name: PropTypes.string.isRequired
}

您可以使用 https://github.com/reactjs/react-codemod#react-proptypes-to-prop-types 替换从 React.PropTypes 到 'prop-types'

的导入