javascript - react-native在chrome调试工具中出现警告,并且不能使用react dev-tools
世界只因有你
世界只因有你 2017-07-03 11:42:25
0
2
1014

1.我使用react@16.0.0-alpha.12react-native@0.45.1 ,在模拟是可以正常使用的,但是在chrome调试工具中出现了警告:

ExceptionsManager.js:71 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. (https://fb.me/migrating-from-react-proptypes)
ExceptionsManager.js:71 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. (https://fb.me/migrating-from-react-create-class)

并且不能使用react dev-tools 进行调试

  1. 我的代码:

/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 * @flow
 */

import React, { Component } from 'react'
import {
  AppRegistry,
  View,
  Text,
  StyleSheet
} from 'react-native'
export default class second extends Component{
  render () {
    return (
      <View style={{
         flex: 1,
        flexDirection: 'column',
        justifyContent: 'center',
        alignItems: 'center',
        backgroundColor: 'ghostwhite'
      }}>
        <Text style={{fontSize: 28, color: 'cadetblue'}}>class extends</Text>
      </View>
    )
  }
  componentDidMount () {
    console.log('==========')
    this.testConsolelog()
  }
  testConsolelog () {
    console.log('e3423423432')
  }
}

const styles2 = StyleSheet.create({
  bigblue: {
    color: 'blue',
    fontWeight: 'bold',
    fontSize: 30,
  },
  red: {
    color: 'red',
  },
});
AppRegistry.registerComponent('second', () => second);
世界只因有你
世界只因有你

全部回复(2)
过去多啦不再A梦

你用的react16中,已经弃用了React.createClass这个方法。

因此react16的版本就无法通过该方法来创建组件了。你必须使用ES6的方式来创建组件了。

class Test extends React.Component {
    ...
}

如果你的代码中用了mixins而必须使用createClass的话,你需要单独引入另外一个工具库。

var createReactClass = require('create-react-class');

另外,React.propTypes也不能使用了,你想要检测props,react16中需要引入一个单独的工具。

import PropTypes from 'prop-types';
習慣沉默

不能使用react dev-tools, 是不是没有勾选允许访问文件地址

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!