Component Lifecycle Phases
Each component has several lifecycle phases that you can leverage to run code at particular times in the process. The three phases are: Mounting, Updating, and Unmounting. Mounting: Mounting is the phase of the component lifecycle when the initialization of the component is completed and the component is mounted on the DOM and rendered for the first time on the webpage. Updating: A component is updated whenever there is a change in the component's state or props. Unmounting: This is the final phase of the lifecycle of the component that is the phase of unmounting the component from the DOM.
Lifecycle Phases in React (in Hindi)
Concepts
1

2

3

Quizzes
Which of these is a phase of the component lifecycle? Select all that apply.
Question 1 of 10
What's the best place to perform side effects in functional components?
Question 1 of 10
Component is mounted every time it rerenders.
Question 1 of 10
Side effect function in useEffect
is always called after component has rendered.
Question 1 of 10
Which of these is an example of side effects in functional components? Select all that apply.
Question 1 of 10
What's true about the code below? Select all that apply.
function Component({ someRandomProps }) { const [count, setCount] = useState(0) document.title = count return <button onClick={() => setCount(count + 1)}>Increment</button> }
Question 1 of 10
What's wrong with the code below?
function Component() { const [count, setCount] = useState(0) useEffect(() => { console.log("I am called after component has rendered") }) return <button onClick={() => setCount(count + 1)}>Increment</button> }
Question 1 of 10
Which of the following statements are true about useEffect
and side effects? Select all that apply.
Question 1 of 10
If the side effect in useEffect is executing on every rerender, what are some of the possible reasons? Select all that apply.
Question 1 of 10
Which of the following statements are true about useEffect
and cleanup function? Select all that apply.
Question 1 of 10
Coding Questions
useEffect to update DOM | easy | 1 | |
useEffect to set timer | medium | 2 | |
Prevent infinite updates in useEffect | medium | 2 | |
Cleanup in useEffect | medium | 2 |