PrepPilotPractise free

React interview questions

Components, hooks, rendering, effects, performance

16 questions · useState · updated November 2026

Practise these as flashcards. One or two lines each; the ones you miss come back first.

Start free

Core questions

What is the difference between props and state in React?

Props are inputs passed from parent to child components and are read-only, while state is local to a component and can be changed by the component itself. Props enable data flow down the tree, and state manages internal data.

How do you update state in a function component?

I use the useState hook. For example, const [count, setCount] = useState(0); and then call setCount(newValue) to update the state.

Why should you use keys in lists?

Keys help React identify which items have changed, been added, or removed, so it can update the DOM efficiently. Without keys, React may misbehave or rerender unnecessarily.

What are the rules of hooks?

Hooks must be called at the top level of a React function component or custom hook, not inside loops or conditions, and only from React functions.

Intermediate questions

Explain how useEffect works and what happens if you omit the dependency array.

useEffect runs after rendering and can perform side effects like fetching data or updating the DOM. If you omit the dependency array, the effect runs after every render, which can cause performance issues or infinite loops.

How does useMemo improve performance?

useMemo caches the result of a computation and only recalculates it when its dependencies change. This prevents expensive calculations from running on every render, improving performance in components with heavy logic.

What is props drilling and how can context help?

Props drilling is passing props through many intermediate components just to reach a deeply nested child. Context allows you to provide data globally so any component can access it directly, reducing unnecessary prop passing.

How would you lazy load a component in React?

I use React.lazy to import the component and Suspense to provide a fallback UI while it's loading. For example: const LazyComp = React.lazy(() => import('./LazyComp')); and <Suspense fallback={<div>Loading...</div>}><LazyComp /></Suspense>.

What is the difference between useCallback and useMemo?

useCallback returns a memoized function, while useMemo returns a memoized value. useCallback is useful for passing stable function references to child components, and useMemo is for caching expensive calculations.

How do you test a button click with React Testing Library?

I render the component, use fireEvent.click or userEvent.click on the button, and then assert the expected change in the DOM. For example, fireEvent.click(screen.getByText('Submit')) and expect(screen.getByText('Submitted')).toBeInTheDocument().

What happens if you forget to include a dependency in a useEffect array?

The effect may use stale values from previous renders, leading to bugs or unexpected behavior. It's important to include all variables used inside the effect in the dependency array.

Senior questions

How does React's reconciliation algorithm work and why are keys important?

React compares the previous and current virtual DOM trees to update only the changed parts. Keys let React match elements between renders, so it can reuse or remove DOM nodes efficiently. Without stable keys, React may reorder or recreate elements incorrectly, causing bugs.

Describe a scenario where improper use of useEffect leads to a bug and how you would fix it.

See the answer in the app, free

How would you optimize a React app with slow initial load times?

See the answer in the app, free

Explain the benefits and trade-offs of using server components in Next.js.

See the answer in the app, free

How do you structure tests for a complex React component using React Testing Library?

See the answer in the app, free

More Frontend topics