(十三)ReactNative--- React.creatClass 和React.component的区别
来源:互联网 发布:手机拍照后期制作软件 编辑:程序博客网 时间:2024/04/26 07:25
1. 使用React.createClass()的格式,
var ReactiveOne = React.createClass({ // constructor:function (props) { // // super(props); // coosole.log('constructor'); // }, getDefaultProps:function () { // console.log(props); this.state = { sex:'boy', }; console.log('getDefaultProps'); }, getInitalState:function () { console.log('getInitalState'); return { tab:'message', eye:'eye', mouth:'mouth' }; }, componentWillMount:function() { this.setState({ sex:'girls', age:16, tab:'sdfdk', eye:'eyeys', mouth:'mouth', }); console.log('componentWillMount'); }, render:function () { console.log('render'); console.log('info_Render','sex:'+this.state.sex,'age:'+this.state.age+'tab:'+this.state.tab+'eye:'+this.state.eye+'mouth:'+this.state.mouth); return (<View style={{backgroundColor:'white'}}></View>); }, ComponentDidMount:function () { console.log('ComponentDidMOunt') },});2. 使用React.component 创建类
class ReactiveOne extends Component{ constructor(props){ super(props); console.log('constructor'); this.state = { sex:'box', }; } componentWillMount() { this.setState({ age: '16', }); console.log('componentWillMount'); } componentDidMount() { console.log('componentDidMount'); this.setState({ sex:'girls', age:'20', }); } render () { console.log('render'); return ( <View style={{backgroundColor:'red',width:width,height:height }}></View> ); } componentWillReceiveProps (nextProps) { console.log('conponentWillReceiveProps',nextProps); } // shouldComponentUpdate() { // console.log('shouldComponentUpdate'); // return true; // } componentWillUpdate() { console.log('componentWillUpdate'); } componentDidUpdate () { console.log('componentDidUpdate'); }}AppRegistry.registerComponent('ReactiveOne', ()=>ReactiveOne);以上是ReactNative 创建类的两种的方式
区别
1.写法上
React.createClass的每一个函数和JS中的一样,可以使用一下两种方式
1. render(){} 正常的函数模式
2. render:function(){} 别名模式 匿名函数
3. 每一个函数的最后要加上 逗号“,”
React.component的每一个和正常的函数写法一样 函数的最后不需要加上逗号“,”
2.The API (via 'extends React.Component') is similar to React.createClass with the exception of getInitialState. Instead of providing a separate getInitialState method, you set up your own state property in the constructor.
初始化函数的区别
0 0
- (十三)ReactNative--- React.creatClass 和React.component的区别
- React.createClass和extends Component的区别
- React:createClass 和 extends Component的区别
- React.createClass和extends Component的区别
- React native 'React.CreatClass is undefind'
- React Router v4中component和render的区别
- React.createClass( ) 和 React.Component( ) 有什么区别?
- React createClass 和 Component 有什么区别
- react---react组件创建,通过React.createClass方法与class App extends Component方法的区别
- react---react组件创建,通过React.createClass方法与class App extends Component方法的区别
- 【React】React.Component小结
- ReactNative——React的API:React和ReactDOM,擅自引入cdnjs的后果
- React Component 的生命周期 API
- Vue和React的区别
- React-native 常见错误:Seems you're trying to access 'ReactNative.Component' from the 'react-native'
- React Native学习笔记(二)--index.android.js 内容和ReactNative组件(<Text>、AppRegistry、View、StyleSheet)及Component
- React Component组件的详细说明和生命周期
- ReactNative之Atom-React的安装
- mfc一个日志库,非常好用,nice
- 网络编程基础(5)-协议概要-TCP的超时重传
- html meta中的viewport
- git学习笔记
- OpenGL 矩阵及变换概念
- (十三)ReactNative--- React.creatClass 和React.component的区别
- Linux基本的架站流程表
- 如何将我的php脚本以守护进程的方式一直运行
- 创建Notification
- 12V85V 降压恒流led驱动方案
- Leetcode 42. Trapping Rain Water
- 解析Rxjava之一---转载自抛物线
- 写入word
- windows上Apache+tomcat实现主备机服务器