React Lifecycle Methods & Effects Flashcards

1
Q

What are the three main phases of a component’s lifecycle?

A

Mounting, Updating, and Unmounting.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the purpose of the componentDidMount lifecycle method?

A

It’s invoked immediately after a component is inserted into the tree and is commonly used for fetching data or initializing subscriptions.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How can you replicate componentDidMount with hooks?

A

Using the useEffect hook with an empty dependency array: useEffect(() => { /* code here */ }, []).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly