In React Native, which of the following are correct characteristics when using Class Components?

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 ý: "Must inherit from Component imported from the react library." và "Needs to use the render() method to return the interface.". Class component được khai báo bằng class TenComponent extends Component, trong đó Component import từ gói react, và bắt buộc có phương thức render() trả về JSX mô tả giao diện; state nằm ở this.state và được cập nhật qua this.setState, props đọc qua this.props. "Does not need to import Text from react-native." sai: muốn hiển thị chữ thì vẫn phải import Text từ react-native, bất kể component viết bằng class hay bằng hàm, vì chữ trần không được đặt trực tiếp trong View. "Can be declared using the same syntax as Function Components." sai vì function component là một hàm nhận props và trả JSX, còn class component dùng cú pháp class với extends và render(), hai cách khai báo khác hẳn nhau.

Cùng chương 2

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