react-native和react用法很相似,如果你用过react,那么学react-native相对容易多了。如果没有学过,也没有关系。
下面是一个react-native的Hello,World!小例子
/**
* Sample React Native App
* https://github.com/facebook/react-native
* @flow
*/
import React, {Component} from 'react';
import { Text } from 'react-native';
export default class Xiao extends Component {
render() {
return (
<Text>Hello,world!</Text>
)
}
}
AppRegistry.registerComponent('xiao', () => Xiao);
registerComponent('xiao',()=>Xiao);
react-native中第一个xiao是文件名,不可以改。第二个Xiao和上面的class Xiao extends Component相对应。
react-native还是建立在react基础之上的,不过react-native有自己的用法.
<Text>Hello,world!</Text>
上面这种写法是一种JSX语法,Text是一个可以显示文本的组件。