image1 image2 image3

HELLO I'M VIET|WELCOME TO MY PERSONAL BLOG|I LOVE TO DO CREATIVE THINGS

React-native Bài 2: Quy trình viết App


GỒM 3 BƯỚC

  • B1: Import Thư viện
  • B2: Viết code Class (Component): Render
  • B3: Đăng ký (Register) Component chính

Để chỉnh sửa đoạn code, các bạn có thể dùng bất cứ 1 IDE nào hỗ trợ ngôn ngữ JavaScript.
Ở đây mình dùng Visual Studio Code -> Open Folder -> MyProject - Mở file App.js

Đoạn code cơ bản của 1 ứng dụng React-native:
//B1 Import thư viện
import React, {Componentfrom "react";
import { 
  AppRegistryViewText 
from "react-native";

//B2 Viết code Class
export default class Demo extends Component {
  render(){
    return(
      <View>
        <Text>Hello World</Text>
      </View>
    );
  }
}

//B3 Register
AppRegistry.registerComponent('Demo', () => Demo);
Hoặc
//B2 Viết code Class
const App = () => (
  <View>
    <Text style={{marginTop: 200marginLeft: 100}}>Hello World</Text>
  </View>
);
export default App;

Và đây là kết quả


Share this:

CONVERSATION

0 nhận xét:

Đăng nhận xét

Thank you!