What is a "context consumer"?
4 phương ánCó giải thích
Các phương án trả lời
Chọn một phương ánLời giảiChọn phương án để mở
Đáp án đúng: "A component that uses data made available within a context.". Context API có hai vai: Provider đặt giá trị vào context qua prop value cho cả cây con bên dưới, còn consumer là component đọc giá trị đó, ngày nay bằng useContext, kiểu cũ là Context.Consumer với render prop. Consumer render lại mỗi khi value của Provider gần nhất thay đổi. "A component that provides data to a context." mô tả Provider, vai ngược với consumer. "A component that only renders static content." sai vì consumer đọc dữ liệu động từ context, có thể đổi theo thời gian. "A component that is responsible for updating the DOM directly" sai vì trong React component chỉ mô tả giao diện, chính React đảm nhận việc commit thay đổi vào DOM.