1.我使用react@16.0.0-alpha.12
, react-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 进行调试
我的代码:
/**
* 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);
你用的react16中,已经弃用了
React.createClass
这个方法。因此react16的版本就无法通过该方法来创建组件了。你必须使用ES6的方式来创建组件了。
如果你的代码中用了mixins而必须使用
createClass
的话,你需要单独引入另外一个工具库。另外,
React.propTypes
也不能使用了,你想要检测props,react16中需要引入一个单独的工具。不能使用react dev-tools, 是不是没有勾选允许访问文件地址