💻
React - The Complete Guide (incl Hooks, React Rout
  • What you'll learn
  • Getting Started
    • Introduction
    • What is React
    • Learning Community
    • Components
    • Writing our First React Code
    • Why Should we Choose React
    • React Alternatives
    • SPA and MPA
      • Single Page Applications
      • Multi Page Applications
    • Course Outline
    • How to get the Most out of This Course
    • Useful Resources & Links
  • Two kinds of application
  • Hiều về let và const
  • Arrow Functions
  • Export và Import
  • Hiểu các tính năng cơ bản & Cú pháp
    • Module Introduction
    • The Build Workflow
    • Node.js Download
    • Using Create React App
    • Understanding the Folder Structure
    • Understanding Component Basics
    • Understanding JSX
    • JSX Restrictions
    • Creating a Functional Component
    • Components & JSX Cheat Sheet
    • Working with Components & Re-Using Them
    • Outputting Dynamic Content
    • Working with Props
    • Understanding the "children" Pro
    • Understanding & Using State
    • Props & State
    • Xử lý các sự kiện bằng các phương thức
    • Bạn có thể nghe những sự kiện nào?
    • Xử lý State
    • Đặt tên Function Components
    • Sử dụng useState() Hook cho xử lý State
    • Stateless vs Stateful Components
    • Truyền Method References giữa các Component
    • Liên kết hai chiều(Two-way Binding)
    • Thêm Styling với Stylesheets
    • Làm việc với Inline Styles
    • Tài nguyên & Liên kết hữu ích
Powered by GitBook
On this page

Was this helpful?

  1. Getting Started

Components

Trọng tâm của các ứng dụng react là components.

Components là các thành phần độc lập, hoạt động giống như một function trong JS. Các component giúp bạn chia UI thành các phần độc lập và có thể tái sử dụng được. Component trả về HTML thông qua render (JSX)

Một component nhận input là một props(viết tắt của properties) nếu có. Trong React có 2 loại component chính, Class component và Method component.

Class component(Stateful):

Là một class ES6, extends React.Component. Bắt buộc phải có hàm render return về HTML.

class Hello extends React.Component{  
   render(){  
   return <h1> Hello, {props.Name} </h1>;  
   }  
}  

Function component(Stateless):

Giống như một Function trong Javascript, chỉ bao gồm immutable properties.

function Hello(props) {  
   return <h1> Hello, {props.Name} </h1>;  
} 

So sánh Function Component và Class omponent

Function

Class component

Là 1 JS function đơn

Là 1 class extends class Component từ React library

Không sử dụng this keyword

Sử dụng this

Dữ liệu đơn

Dữ liệu phức

Sử dụng hooks để thay đổi giá trị của properties

Sử dụng State và setState để thay đổi giá trị của properties

PreviousLearning CommunityNextWriting our First React Code

Last updated 4 years ago

Was this helpful?

Tham khảo thêm:

https://www.c-sharpcorner.com/learn/reactjs-for-beginners/components-in-react
https://reactjs.org/docs/components-and-props.html