
Component Lifecycle
Mounting, updating, unmounting, useEffect cleanup, dependencies array, lifecycle patterns
1What is mounting in a React component?
What is mounting in a React component?
Answer
Mounting is the phase where a component is created and inserted into the DOM for the first time. During this phase, React initializes state, executes construction code and performs the first render. This is the ideal moment to trigger API calls or initialize subscriptions via useEffect.
2What is unmounting in a React component?
What is unmounting in a React component?
Answer
Unmounting is the phase where a component is removed from the DOM and destroyed. This phase occurs when the component is no longer needed, for example during a route change or rendering condition. This is the critical moment to clean up resources: cancel timers, close WebSocket connections and remove event listeners to prevent memory leaks.
3When does the function passed to useEffect execute by default?
When does the function passed to useEffect execute by default?
Answer
By default, useEffect executes after every component render, including the first render and all subsequent re-renders. This asynchronous execution allows not blocking the user interface. To control this behavior, it's possible to use the dependencies array as second argument to limit executions only when certain values change.
What is the purpose of the dependency array in useEffect?
What does it mean to pass an empty array [] as dependencies to useEffect?
+15 interview questions
Other React / Next.js interview topics
JavaScript Essentials
React Fundamentals
React Hooks
React Router
State Management with Context
Forms & Controlled Components
Data Fetching & API
React Query (TanStack Query)
Styling & CSS-in-JS
Next.js Fundamentals
TypeScript with React
Next.js Data Fetching
Next.js Server Actions
Next.js Routing & Navigation
Next.js API Routes
Next.js Metadata & SEO
Next.js Middleware & Auth
React Testing
Zustand State Management
React Performance Optimization
Error Boundaries & Error Handling
Advanced React Patterns
Next.js Advanced Features
Next.js Deployment & Production
Architecture & Design Patterns
React Server Components
Next.js Internationalization
React Security & Best Practices
Master React / Next.js for your next interview
Access all questions, flashcards, technical tests, code review exercises and interview simulators.
Start for free