Which of the following statements is true about how TextInput 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 án
Lời giảiChọn phương án để mở
Đáp án đúng gồm hai ý: "TextInput is often linked to a state variable to display the current value and update when the user changes the content." và "The value property in TextInput should be linked to a state variable so that the component can control the displayed content (controlled component).". Mẫu chuẩn là controlled component (component được điều khiển): khai báo state bằng useState, truyền state vào prop value và truyền hàm set vào onChangeText; mỗi lần người dùng gõ, onChangeText nhận chuỗi mới, state đổi, component render lại và TextInput hiển thị đúng giá trị trong state, nhờ đó dễ kiểm tra hợp lệ hay định dạng dữ liệu. "TextInput cannot use state to store the value entered by the user." sai, vì dùng state chính là cách phổ biến nhất như vừa mô tả. "The onChangeText event is used to update the props of TextInput directly." sai vì props là chỉ đọc, không thể sửa trực tiếp; onChangeText chỉ đưa chuỗi mới cho ta cập nhật state, rồi state mới được truyền lại vào value.

Cùng chương 2

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