Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Trong bài này chúng ta sẽ tìm hiểu về các components trong React và cách quản lý chúng.

STATELESS EXAMPLE

Chúng ta tiếp tục sử dụng lại App.js, thêm vào 2 components đó là Header và Content, App sẽ chứa 2 component mới thêm vào, sau đó ta export thằng App.

...

Code Block
languagejs
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App.jsx';

ReactDOM.render(<App />, document.getElementById('root'));

Và kết quả ta được:

...

STATEFULL EXAMPLE

Trong ví dụ này chúng ta sẽ thêm state vào trong App component, state sẽ là 1 mảng object, chúng ta thay content thành TableRow component, TableRow sẽ nhận các giá trị state của component cha là App. (Chúng ta sẽ tìm hiểu kĩ hơn về state và props ở các bài sau)

...