眼下React Native(之後簡稱RN)愈來愈火,我也要投入到學習當中。對於一個前端來講,仍是有些難度。由於本人以爲這是一個App開發的領域,天然是不一樣。編寫本文的時候,RN的版本爲0.21.0。咱們立刻以代碼進入今天的學習。前端
'use strict'; import React, { AppRegistry, Component, StyleSheet, Text, View } from 'react-native'; class Hello extends Component { render() { return ( <View> <Text>{ this.props.title}</Text> <Text>{ this.props.text}</Text> </View> ); } } class HelloComponent extends React.Component{ constructor (props) { super(props); this.state = { appendText: '' }; } _setText() {
this.setState({appendText: ' Native!'}); } render() { return ( <View> <Text onPress={this._setText.bind(this)}> {this.props.text + this.state.appendText} </Text> </View> ); } } class learn01 extends Component { render() { const pros = { text: 'hi', title: 'title' } return ( <View> <View style={{height:30}} /> <Hello {...pros} /> <HelloComponent text="React"/> </View> ); } }
簡要分析:react
今天到此爲止,下次見。es6