javascript - react-native在chrome偵錯工具中出現警告,且不能使用react dev-tools
世界只因有你
世界只因有你 2017-07-03 11:42:25
0
2
1015

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學習者快速成長!