Skip to content

Latest commit

 

History

History
25 lines (17 loc) · 962 Bytes

示例教程.md

File metadata and controls

25 lines (17 loc) · 962 Bytes

示例教程:Hello World

Hello World

根据历史悠久的“传统”,我们也来写一个“Hello, world!”:

import React, { Component } from 'react';
import { Text, View } from 'react-native';

export default class HelloWorldApp extends Component {
render() {
    return (
        <View style={{ flex: 1, justifyContent: "center", alignItems: "center" }}>
        <Text>Hello, world!</Text>
        </View>
    );
}
}

你可以新建一个项目,然后用上面的代码覆盖你的App.js文件,然后运行看看。

组件

上面的代码定义了一个名为HelloWorldApp的新的组件(Component)。你在编写 React Native 应用时,肯定会写出很多新的组件。而一个 App 的最终界面,其实也就是各式各样的组件的组合。组件本身结构可以非常简单——唯一必须的就是在render方法中返回一些用于渲染结构的 JSX 语句。