What is the difference between the render() method and the commit() method in React?
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: "There is no commit() method in React.". Theo tài liệu react.dev, render và commit là hai GIAI ĐOẠN trong cách React cập nhật màn hình: ở giai đoạn render, React gọi component để tính ra giao diện mới và so với lần trước; ở giai đoạn commit, React áp các thay đổi đó vào DOM, sau đó mới chạy effect. Commit là tên một giai đoạn nội bộ, React không cung cấp phương thức commit() nào để component viết ra hay gọi. "The render() method defines the component's structure, while the commit() method handles side effects." là phương án mà đề in chấm làm đáp án và cũng dễ bị chọn nhất: vế render đúng, và nếu hiểu commit là giai đoạn thì ý cập nhật DOM rồi chạy effect cũng gần đúng, nhưng câu này gọi commit là một phương thức như render(), mà phương thức đó không tồn tại, nên đáp án chốt là phát biểu phủ nhận. "The render() method handles events, while the commit() method defines the component's structure." sai vì render không xử lý sự kiện, và cũng dựa trên phương thức commit không có thật. "The render() method is called before the component is mounted, while the commit() method is called after the component is mounted." sai vì render được gọi cả ở lần mount lẫn mỗi lần cập nhật, và ở phần sau vẫn là phương thức commit không có thật.
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