Choose the correct answer about how the Switch component works in React Native:
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 gồm hai ý: "To accurately reflect user behavior (i.e., when the user toggles the switch), you need to handle the onValueChange event and update the value of the corresponding value prop." và "Switch is a controlled component, meaning you need to update its value through the onValueChange callback." Switch là controlled component (thành phần được điều khiển): vị trí bật/tắt hiển thị luôn lấy từ prop value, nên khi người dùng gạt, onValueChange được gọi với giá trị boolean mới và ta phải cập nhật state (ví dụ setIsEnabled) để value đổi theo; nếu không cập nhật, công tắc bật ngược về giá trị cũ. Phát biểu "Switch operates in an uncontrolled manner" sai vì Switch không tự giữ trạng thái, thiếu value thì nó không phản ánh lựa chọn của người dùng. Phát biểu "is only used to display the current state of the Switch" sai vì onValueChange chính là nơi nhận thay đổi và cập nhật logic ứng dụng, không phải chỉ để hiển thị.
Cùng chương 2
A View component can be nested inside other views. Select the correct option.Có lời giảiCâu hỏiWhich component is the foundation for all React Native components and provides the base functionality for rendering elements to the screen?Có lời giảiCâu hỏiWhich keyword is used to extend a component from a base component?Có lời giảiCâu hỏiCả 54 câu của chủ đề54 câu