React Lifecycle Methods & Effects Flashcards
1
Q
What are the three main phases of a component’s lifecycle?
A
Mounting, Updating, and Unmounting.
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.
3
Q
How can you replicate componentDidMount with hooks?
A
Using the useEffect hook with an empty dependency array: useEffect(() => { /* code here */ }, []).