Props and state

1. Props

Props là cách truyền dữ liệu từ component cha đến component con.

Component con giao tiếp với component cha sẽ qua việc Emit events

Cách dùng

  • Component cha truyền dữ liệu cho component con

  • Component con nhận dữ liệu trừ Props và tiến hành xử lý

2. State

State là một object chứa dữ liệu hoặc thông tin về component.

Các thao tác với state

  • Khởi tại state

  • Update State

3. React Lifecycle

React có 3 trạng thái:

  • Mounting : khi được thêm vào DOM

  • Unmounting : khi bị Remove khỏi DOM

  • Updating : making changes to nodes already in the DOM

4. Handle an event

Sự khác biệt giữa HTML và React

For example, the HTML:

is slightly different in React:

2 cách để nhận biết event: nguyên nhân this trong html sẽ là window chứ không phải class hiện tại.

  • Sử dụng binding

  • Sử dụng arrow function

  • Sử dụng arrow function in callback

Vấn đề passing arguments to Event Handler

Inside a loop, it is common to want to pass an extra parameter to an event handler. For example, if id is the row ID, either of the following would work:

Last updated

Was this helpful?