Câu hỏi phỏng vấn Reactjs
Câu hỏi

Which lifecycle methods of class component is replaced by useEffect in functional component?

Câu trả lời

The useEffect hook in React functional components replaces several lifecycle methods of class components. Specifically, it serves as a replacement for the following lifecycle methods:

  1. componentDidMount: This lifecycle method is used in class components to perform actions after the component has been inserted into the DOM. In functional components, useEffect with an empty dependency array ([]) mimics this behavior, running only once after the initial render[1][2][3][4].

  2. componentDidUpdate: In class components, this method is invoked after updates to the component, such as changes in state or props. useEffect can replicate this by including specific dependencies in its dependency array. When any of these dependencies change, the effect runs again, thus mimicking the componentDidUpdate method[1][2][3][4].

  3. componentWillUnmount: This method is used for cleanup activities when a component is about to be removed from the DOM. useEffect handles this through a return function that specifies cleanup actions. This function is executed when the ...

middle

middle

Gợi ý câu hỏi phỏng vấn

middle

What are Error Boundaries in ReactJS?

middle

What does Batching mean in ReactJS?

middle

Why do class methods need to be bound to a class instance?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào