What does the render method in a React component do?
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: "It returns the JSX that describes the UI". Trong component dạng lớp, render là phương thức bắt buộc duy nhất; React gọi nó mỗi khi cần vẽ component và nó trả về JSX mô tả giao diện tương ứng với this.props và this.state hiện tại. render phải thuần (pure): cùng props và state thì trả cùng kết quả, không sửa state, không gọi API. "It manages state updates" sai vì cập nhật state làm qua this.setState, gọi trong hàm xử lý sự kiện hoặc phương thức vòng đời, còn gọi setState trong render sẽ gây vòng lặp render vô hạn. "It handles side effects" sai vì side effect như đăng ký sự kiện hay hẹn giờ được đặt trong componentDidMount và componentDidUpdate, ở component hàm là useEffect. "It fetches data from an API" sai vì lấy dữ liệu cũng là side effect, thường đặt trong componentDidMount; gọi API trong render sẽ gửi request ở mỗi lần render.
Cùng phần 4
How can you ensure that a prop is passed as an array with at least one element?Có lời giảiCâu hỏiHow can you pass parameters to an event handler in React?Có lời giảiCâu hỏiWhich of the following is used to pass a function from a parent component to a child component?Có lời giảiCâu hỏiCả 40 câu của chủ đề40 câu