Skip to content
CompanyBenchCompanyBench

Advanced React interview questions and answers

Advanced React interview questions with answers on hooks, custom hooks, performance, Context vs Redux, compound components, testing and React.memo.

Questions for senior React roles on hooks, performance tuning, the Context API, state management and component patterns. Allow 45-60 minutes.

Hooks

What are custom hooks and why would you write one?

A custom hook is a reusable function built on React's hooks. It lets several components share logic without copying code.

What is the difference between useEffect and useLayoutEffect?

useEffect runs asynchronously after the browser paints. useLayoutEffect runs synchronously before paint, which is what you need when measuring DOM layout.

How do you build a debounced search with hooks?

Use useEffect with a setTimeout and clear it in the cleanup function. Keep the timeout id in a useRef so it survives re-renders.

What is useReducer and when should you use it?

An alternative to useState for complex state with several sub-values, or where the next state depends on the previous one.

What are the rules of hooks and why do they exist?

Call hooks only at the top level, and only from function components or custom hooks. This keeps the order of hook calls the same on every render.

Performance and state

How do you improve performance in a React app?

Memoise with React.memo, useMemo and useCallback, lazy-load and code-split, and virtualise long lists.

What is React.memo and how does it work?

A higher-order component that memoises a function component. It re-renders only when its props change, using a shallow comparison.

When should you use the Context API instead of Redux?

Context suits light, rarely changing state such as theme, auth or locale. Redux suits complex global state with a lot of logic.

Patterns and testing

What is the compound component pattern?

Related components share state implicitly through context, which gives users of the component a clean, flexible API.

What does React Testing Library add?

It tests the UI the way a user interacts with it, through DOM elements, rather than through component internals.

Related: React developer interview questions, hire React developers and React developer salaries in India.