Which of the following statements most accurately describes the difference between props and state in React?

4 phương ánCó giải thích

Các phương án trả lời

Chọn một phương án
Lời giảiChọn phương án để mở
Đáp án đúng gồm hai ý: "props are used to pass data from a parent component to a child component, while state is used to manage the internal data of a component." và "state can be changed by the component itself, while props are read-only for the receiving component.". props là dữ liệu component cha truyền xuống con, phía con chỉ được đọc; state là dữ liệu nội bộ do chính component sở hữu, được đổi bằng this.setState hoặc hàm set của useState, và mỗi lần đổi sẽ khiến component render lại. "props allow the component to automatically update the displayed data based on user interactions." sai vì tương tác của người dùng được phản ánh bằng cách cập nhật state; props chỉ đổi khi component cha truyền xuống giá trị mới. "state should only be passed as a parameter between components and should not be used to store internal data." đảo ngược bản chất: state chính là nơi lưu dữ liệu nội bộ, còn khi muốn chia sẻ thì giá trị state được truyền xuống con dưới dạng props.

Cùng chương 6

Xuất hiện trong 1 bộ đề