React Frontend Interview Questions for Java Full Stack with React
25 React Frontend questions with answers for java full stack with react roles — 7 easy, 12 medium, 6 hard.
About React Frontend
React is the most popular library for building the frontend of Java full stack applications. This topic covers components, props and state, hooks like useEffect, useMemo and useReducer, custom hooks, context and state libraries, routing with protected routes, API calls with Axios, token handling and performance techniques such as code splitting and virtualization.
Sheet progressStart practicing
3 QUESTIONS FREESign up to unlock the full question bank and track your progress.Unlock every question and answer, then continue practising company-wise and package-wise.
React is a JavaScript library for building user interfaces from reusable components. Components describe what the UI should look like for a given state, and React updates the browser DOM when the state changes. The virtual DOM is a lightweight in-memory tree of the UI. On each update, React compares the new tree with the previous one and applies only the minimum real DOM changes, which keeps updates efficient and the code declarative.
Props are inputs passed from a parent component and are read-only inside the child. State is data owned by a component that can change over time, managed with useState or useReducer, and changing it triggers a re-render. For example, a ProductCard receives a product as props, while a cart counter keeps its quantity in state. When two components need the same state, lift it up to their common parent.
03
Why does React need a key prop when rendering lists?
Keys help React match list items between renders, so it knows which items were added, removed or moved. Use a stable unique ID from the data, such as product.id. Using the array index as key causes bugs when items are reordered or deleted, because state and input values can attach to the wrong row. Keys only need to be unique among siblings, and they are not passed to the component as a prop.
04
How do you take feedback from a senior on your React code?
Situation: in my first month, a senior reviewer left many comments about large components and duplicated fetch logic. Task: improve the code and learn from it. Action: I thanked him, asked for a short call to understand the reasoning, split the component, and wrote a custom hook for data fetching. Result: the pull request was approved, and the hook was reused in three other screens. I now self-review using his checklist.
This is prop drilling, which makes intermediate components depend on data they do not use. For global, rarely changing data like the logged-in user or theme, create a context with a provider at the top and read it with useContext through a custom hook such as useAuth. Alternatively, use component composition, passing ready-made elements as children. For complex shared state, a store like Zustand or Redux Toolkit is suitable.
07
How do you handle a disagreement with a UI designer about a screen?
Situation: a designer wanted a complex animated table that would be slow on low-end phones. Task: protect performance without dismissing the design. Action: I built a quick prototype, showed the lag on a budget Android device and proposed a lighter animation with the same feel. Result: the designer agreed, the page stayed fast, and we started reviewing performance impact together during design discussions.
useEffect runs after the component renders. With no dependency array it runs after every render, with an empty array it runs once after mount, and with values like [userId] it runs again whenever those values change. Return a cleanup function to cancel subscriptions, timers or requests before the next run or on unmount. Missing dependencies cause stale data, so follow the exhaustive-deps lint rule. Effects are for syncing with external systems, not for computing derived values.
09
What is the difference between controlled and uncontrolled components?
In a controlled component, form input values live in React state and change through onChange, so React is the single source of truth, which makes validation and conditional UI easy. In an uncontrolled component, the DOM keeps the value and you read it through a ref when needed, which needs less code and suits simple forms or file inputs. Libraries like React Hook Form use uncontrolled inputs for better performance in large forms.
useMemo caches the result of an expensive calculation until its dependencies change, such as filtering and sorting a big list. useCallback caches a function reference, which matters when passing callbacks to children wrapped in React.memo or used in effect dependencies. Do not wrap everything, because memoization itself has a cost. The React Compiler, released as stable in 2025, can add much of this memoization automatically in supported projects.
11
When would you use the Context API and when a state library like Redux Toolkit or Zustand?
Context is good for passing low-frequency global values such as theme, language or the logged-in user without prop drilling. Every consumer re-renders when the context value changes, so it is not ideal for fast-changing data. Redux Toolkit or Zustand suit larger shared client state with many updates, selectors and dev tools. Server data like API responses is often best handled by TanStack Query, which adds caching and refetching.
12
What is a custom hook and why would you write one?
A custom hook is a function whose name starts with use and which calls other hooks, letting you reuse stateful logic across components. Examples are useFetch for loading data, useDebounce for search input and useAuth for the current user. Each component calling the hook gets its own independent state. Custom hooks keep components focused on rendering and make logic easier to test, much like extracting a service in backend code.
13
How do code splitting and lazy loading work in React?
Code splitting breaks the JavaScript bundle into smaller chunks loaded on demand, which improves first load time. React.lazy with a dynamic import, such as const Reports = lazy(() => import('./Reports')), loads the component only when it renders, and Suspense shows a fallback while it loads. Splitting by route is the most common pattern. Bundlers like Vite create the chunks automatically from dynamic imports.
14
Fetch a list of products from an API and show loading and error states.
Usually useEffect sets state and has a dependency that changes on every render, or has no dependency array at all. A common case is an object or function created inside the component and listed as a dependency, so it is new each time. Fix it by using a correct dependency array, moving the object outside the component, or memoizing it with useMemo or useCallback. Also check that you are not calling setState directly during render.
18
After calling setCount(count + 1), console.log(count) still shows the old value. Why?
State updates are scheduled, not applied immediately. The count variable in the current render is a constant snapshot, so logging right after setState shows the old value; the new value appears in the next render. React also batches multiple updates. When the next state depends on the previous one, use the updater form setCount(c => c + 1), which works correctly even when called several times. Use useEffect to react to the updated value.
19
What is the biggest full stack project you have built?
I built a job portal using React with Vite, Spring Boot 3, Spring Security with JWT and MySQL. Recruiters could post jobs and candidates could apply and track status. I designed the REST APIs, implemented role-based access, added pagination and search, and used TanStack Query on the frontend. I deployed it with Docker and a CI pipeline. The hardest part was file upload for resumes, which I solved with pre-signed object storage URLs.
20
What triggers a re-render in React, and how does reconciliation decide what to update?
A component re-renders when its state changes, its parent re-renders, or a context it uses changes. Props changing is not itself the trigger; parent re-render is. During reconciliation React compares element types: a different type at the same position destroys and recreates the subtree, while the same type updates props. Keys identify list children. React.memo skips a child re-render when its props are shallowly equal.
21
Create a protected route in React Router that redirects unauthenticated users to login.
Rendering thousands of DOM nodes is costly. Use server-side pagination or infinite scroll so the API returns only one page. If all rows must be scrollable, use list virtualization with a library like TanStack Virtual or react-window, which renders only visible rows. Memoize row components with React.memo, keep stable keys, avoid inline heavy calculations, and debounce filters. Profile with React DevTools Profiler to confirm which components are slow.
24
Where should a React app store the JWT, and what are the trade-offs?
localStorage is simple but any XSS script can read it. In-memory storage is safer but is lost on refresh. The commonly recommended pattern is a short-lived access token kept in memory and a refresh token in an HttpOnly, Secure, SameSite cookie that JavaScript cannot read, used to get new access tokens. Cookies need CSRF protection for state-changing calls. Whatever you choose, prevent XSS with proper escaping and a Content Security Policy.
25
In a search box, older API responses sometimes overwrite newer results. How do you fix this race condition?
Each keystroke starts a request, and responses can arrive out of order. Debounce the input by about 300 milliseconds so fewer requests are sent. In the effect, cancel the previous request with AbortController in the cleanup function, or keep an ignore flag so stale responses are discarded. Libraries like TanStack Query handle this automatically by keying queries on the search term and ignoring outdated results.
Frequently asked questions
How important is React Frontend in Java Full Stack with React interviews?
React is the most popular library for building the frontend of Java full stack applications. This topic covers components, props and state, hooks like useEffect, useMemo and useReducer, custom hooks, context and state libraries, routing with protected routes, API calls with Axios, token handling and performance techniques such as code splitting and virtualization.
How should I use the React Frontend sheet?
Go top to bottom — easy to hard. Answer before opening each answer, tick what you solved and save misses to Last-Minute Revision.