Information Technology
React Interview Questions & Answers
Meta JavaScript component library for managing complex web interface views.
Accessibility (a11y) in React
All 5 questionsAccessibility means building an app that everyone can use, including people who use screen readers, keyboards only, or have vision or motor difficulties. In React this means using…
ARIA attributes give extra information to screen readers when plain HTML is not enough to describe what an element does. For example, aria label describes a button that only has an…
A custom component built from a div or span does not get keyboard behavior automatically the way a real button does. To fix this you add tabIndex so it can be focused, and an onKey…
When a modal opens, focus should move into the modal automatically, and it should stay trapped inside the modal while it is open so a keyboard user cannot accidentally tab to conte…
The eslint plugin jsx a11y catches common accessibility mistakes right inside your code editor while you type. The axe DevTools browser extension and Lighthouse in Chrome scan a ru…
Animation in React (Framer Motion & React Spring)
All 5 questionsFramer Motion is a popular animation library for React. Instead of writing complex CSS animations by hand, you use its motion components and simply describe the starting state, the…
React Spring is based on physics, meaning you describe how something should move using spring settings like tension and friction rather than a fixed duration. This often looks more…
- How would you animate a list where items can be added or removed, such as a shopping cart? Intermediate
Framer Motion provides an AnimatePresence component that detects when an item is removed from a list and plays an exit animation before it actually disappears from the screen, inst…
Animations run smoothly when they only change properties like transform and opacity, since browsers can handle those using the graphics card without recalculating the whole page la…
Framer Motion has a whileHover prop that lets you describe how a component should look only while the mouse is hovering over it, and it automatically animates back to normal once t…
Build Tools & Bundlers (Vite, Webpack & CRA)
All 5 questionsA build tool takes all your separate JavaScript, CSS, and image files and combines them into a small number of optimized files that a browser can load quickly. It also converts mod…
- Why has Vite become more popular than Create React App for starting new React projects? Intermediate
Vite starts a development server almost instantly because it only processes the files a page actually needs right away, instead of bundling the entire app upfront like older tools…
Minification removes unnecessary spaces, comments, and shortens variable names in the final JavaScript file, without changing what the code actually does. This makes the file much…
A build tool can split code so that a page only downloads the JavaScript it actually needs right away, instead of one giant file containing the entire app. Extra pieces of the app…
- What is the difference between a development server and a production build in a React project? Beginner
A development server, started with a command like npm run dev, shows helpful error messages and updates the page instantly as you save changes, but the code is not optimized for sp…
Class Components & Legacy Lifecycle Methods
All 5 questionsA class component is written using JavaScript class syntax and extends React.Component. It manages state using this.state and this.setState, and it needs a render method that retur…
- What does componentDidMount do in a class component and what is its equivalent using hooks? Intermediate
componentDidMount runs one time, right after a component first appears on the screen. It is commonly used to fetch data from a server or set up something like a timer. Using hooks,…
Error boundaries need two special lifecycle methods, getDerivedStateFromError and componentDidCatch, which are only available on class components. There is currently no hook versio…
- What is componentDidUpdate used for, and what mistake should you watch out for when using it? Advanced
componentDidUpdate runs every time a component re renders after its props or state change, which makes it useful for reacting to a specific value changing, such as fetching new dat…
State is first defined inside the constructor using this.state as a plain object. To change it later, you always call this.setState with the new values, and React will re render th…
Code Splitting & Lazy Loading
All 5 questionsCode splitting means breaking your app's JavaScript into smaller separate files instead of one huge file. The browser only downloads the small piece it needs for the current page,…
- How do React.lazy and Suspense work together to load a component only when it is needed? Intermediate
React.lazy takes a function that dynamically imports a component, and returns a special component that only actually loads that code the first time it is rendered. Suspense wraps a…
Each page in a router setup can be wrapped in React.lazy, so that visiting the home page does not force the browser to also download the code for the about page or the contact page…
You can call the same dynamic import function used inside React.lazy ahead of time, such as when the user hovers over a link, so the code is already downloaded and ready by the tim…
React needs a Suspense boundary somewhere above a lazy loaded component to know what to show while that component's code is still downloading. If there is no Suspense wrapper anywh…
Component Composition & Children Props
All 5 questionsComponent composition means building complex user interfaces by combining small, simple components together, instead of writing one giant component that does everything. This makes…
The children prop automatically holds whatever content is placed between the opening and closing tags of a component. It lets a component wrap around any content without needing to…
Prop drilling happens when you pass a prop through many components that do not actually need it, just so it can reach a component deep inside the tree. Composition can avoid this b…
Instead of only accepting one block of children, a component can accept several props that each hold their own piece of content, such as a header slot and a footer slot. This gives…
Nesting as children is the natural way of writing JSX where content sits between opening and closing tags, and it reads like regular HTML. Passing a component as a named prop is us…
Components & JSX
All 5 questionsJSX is a special syntax that lets you write HTML looking code directly inside your JavaScript files. It makes it much easier to see what a component will look like on the screen, a…
A component is a reusable piece of the user interface, like a button, a form, or an entire page. Today almost all components are function components, which are plain JavaScript fun…
- How do you embed a JavaScript expression inside JSX? Intermediate
You wrap any JavaScript expression in a single pair of curly braces directly inside your JSX. This lets you display variables, call functions, or run small calculations right where…
Under the hood, JSX is converted into a single function call that returns one value, so it cannot return two separate elements sitting side by side. Wrapping everything in one pare…
In JSX you use className instead of class, because class is already a reserved word in JavaScript used for defining classes. Everything else about applying a CSS class works exactl…
Concurrent Hooks (useTransition, useDeferredValue & useLayoutEffect)
All 5 questionsuseTransition lets you mark a state update as not urgent, so React can keep the screen responsive to more important things, like typing in a search box, while a slower update, like…
- How does useDeferredValue help improve performance when rendering a large list based on user input? Advanced
useDeferredValue lets you keep showing an older, slightly outdated version of a value while React works on rendering the newer version in the background. This means the input field…
useLayoutEffect runs right after React updates the screen but before the browser actually paints anything visible to the user. This is useful when you need to measure something on…
Use useTransition when you control the actual state update that is slow, since it lets you wrap that specific update in startTransition. Use useDeferredValue when you receive a val…
Imagine typing into a search box that filters a list of ten thousand items on every keystroke. Without useTransition, each keystroke might feel slightly delayed because the browser…
Conditional Rendering & Lists (Keys)
All 5 questionsYou can use a regular JavaScript if statement before the return, a ternary expression directly inside JSX, or the double ampersand operator when you only want to show something in…
You use the array's map method to turn each item in a list into a piece of JSX, and each resulting element needs a unique key prop so React can keep track of which item is which, e…
When items are added, removed, or reordered, the index of each item can change even though the actual item stayed the same. This confuses React into thinking the wrong item changed…
You check the array's length before mapping over it, and show a friendly message instead of an empty list when there is nothing to display. This gives users clear feedback instead…
When there are many possible cases, a lookup object mapping each case to a component is often cleaner and easier to read than a long chain of if or else if statements, and it also…
Context API
All 5 questionsContext lets you share a value, such as the current logged in user or a color theme, with many components at once, without needing to manually pass it down as a prop through every…
First you create the context using createContext, then you wrap the part of your app that needs access with a Provider component and give it a value, and finally any component insi…
Every component that reads a piece of Context using useContext will re render whenever that Context's value changes, even if the component only cares about a small part of that val…
You can write a small custom hook that calls useContext internally and throws a clear, helpful error if it is used outside its matching Provider. This saves other developers from h…
Context is commonly used for information that many parts of an app need at once, such as the currently logged in user, the selected language for translations, or shopping cart cont…
Custom Hooks
All 5 questionsA custom hook is simply a JavaScript function whose name starts with use, and it lets you reuse stateful logic between different components without repeating the same code. It can…
- How would you write a custom hook to fetch data from an API and share that logic across components? Intermediate
You move the fetching logic, along with loading and error state, inside a custom hook, and return whatever the component needs, such as the data, a loading flag, and any error. Eve…
- What are the rules you must follow when writing and using hooks, including custom hooks? Intermediate
Hooks must always be called at the top level of a function component or another hook, never inside loops, conditions, or nested functions. This ensures React can correctly keep tra…
A debounce hook waits until the user has stopped typing for a short period before updating the final value, avoiding unnecessary work, like sending a network request, on every sing…
A custom hook can use other hooks like useState and useEffect internally, giving it access to a component's state and lifecycle, while a plain helper function cannot use hooks at a…
Data Fetching (React Query & SWR)
All 5 questionsFetching data with plain useEffect means you have to manually handle loading states, errors, caching, and refetching yourself every single time. React Query and SWR handle all of t…
- How does automatic caching work in React Query, and why does it make an app feel faster? Intermediate
React Query stores the result of each request under a unique key, and if a component asks for that same key again, it shows the cached data instantly while quietly checking in the…
React Query provides a useMutation hook specifically for actions that change data on the server, like creating, updating, or deleting something. After the mutation succeeds, you ca…
SWR immediately shows any data it already has cached, even if it might be slightly outdated, while quietly fetching a fresh copy in the background at the same time. Once the fresh…
Writing your own fetch logic in every component means repeating the same loading, error, and caching code over and over, and it is easy to make small mistakes, like forgetting to c…
Deployment & Production Builds
All 5 questionsA production build is the final, optimized version of your app, created by running a build command like npm run build. It produces smaller, faster files with helpful development wa…
- What are some popular hosting platforms for deploying a React app, and how do they differ? Intermediate
Vercel and Netlify are very popular for React apps because they connect directly to your code repository and automatically build and deploy your site every time you push new change…
Environment variables let you keep configuration values, like an API address, separate from your code, so the same codebase can behave differently in development versus production.…
A continuous deployment pipeline automatically runs your tests, builds your app, and deploys it to a live server every time new code is pushed to your repository, without anyone ne…
The production build removes helpful development warnings and changes how the code is packaged, so a bug that never showed up during development can sometimes appear only in the pr…
Design Patterns in React
All 5 questionsThis pattern separates a component into two parts. The container component handles data fetching and logic, while the presentational component only receives data through props and…
Compound components let several related components work together and share hidden state behind the scenes, while still letting the person using them arrange the pieces however they…
- What is the controlled component pattern and why is it considered a best practice for forms? Intermediate
In a controlled component, the form input's value is always driven by React state, meaning React is the single source of truth for what the input shows. This makes it easy to valid…
The provider pattern wraps a piece of your app in a component that supplies shared data and functions to everything inside it, usually built using the Context API. This keeps relat…
- What is the single responsibility principle and how does it apply to writing React components? Beginner
The single responsibility principle means each component should do just one clear thing, such as displaying a single piece of information or handling one specific interaction. Brea…
Effects & Lifecycle
All 5 questionsuseEffect lets you run code that reaches outside of React, such as fetching data, setting a timer, or updating the page title, after a component renders. It runs after the screen u…
The dependency array tells React exactly which values, when changed, should cause the effect to run again. An empty array means the effect runs only once when the component first a…
If an effect sets up something like a timer, a subscription, or an event listener, you should return a cleanup function from useEffect that removes it. React automatically calls th…
A race condition can happen when a component fetches data, the dependency changes again quickly, and an older, slower request finishes after a newer one, showing outdated results b…
Code inside useEffect runs after React has already updated the screen, making it safe for things like fetching data or interacting with browser APIs. Code that runs directly during…
Error Boundaries
All 5 questionsAn error boundary is a special component that catches JavaScript errors happening anywhere in its child components, and shows a friendly fallback message instead of letting the ent…
You add the componentDidCatch method to your error boundary class, which receives the actual error object and information about where it happened. This is a good place to send the…
- Why does React not catch errors that happen inside event handlers, like an onClick function, using error boundaries? Intermediate
Error boundaries only catch errors that happen while React is rendering, updating lifecycle methods, or during construction. An error thrown inside an event handler happens outside…
- How would you build a reusable error boundary that lets the user retry after an error occurs? Advanced
You add a button inside the fallback view that resets the error boundary's state back to no error, allowing React to attempt rendering the children again from scratch. This gives u…
A good approach is placing one error boundary around your entire app as a safety net, and then placing smaller, more specific error boundaries around individual features or section…
Forms: Controlled & Uncontrolled Components
All 5 questionsA controlled input gets its current value from React state and updates that state every time the user types, using the onChange event. This means React always knows exactly what th…
An uncontrolled input keeps its own value internally in the actual HTML element, similar to how forms worked before React existed. Instead of tracking every keystroke in state, you…
You keep track of any validation errors in state alongside your form values, and check the input against your rules either as the user types or when they try to submit. If a rule f…
React Hook Form lets you register each input once and handles tracking its value, validation, and errors internally, without causing your component to re render on every single key…
By default, submitting an HTML form reloads the entire page. In React, you call preventDefault on the submit event inside your onSubmit handler, which stops the browser's default r…
Higher-Order Components (HOCs)
All 5 questions- What is a higher order component in React? Intermediate
A higher order component, often shortened to HOC, is a function that takes a component as input and returns a new, enhanced component with extra behavior added, without changing th…
A withAuth higher order component can check whether a user is logged in, and either render the actual protected page or redirect them to a login page instead. This lets you protect…
Wrapping a component in several higher order components can create a confusing nested structure, sometimes called wrapper hell, making it harder to trace where a certain prop actua…
You spread any extra props received by the wrapper component down onto the wrapped component, ensuring the wrapped component still receives everything it normally would, plus whate…
- What is a simple example of a higher order component that adds a border style to any component? Beginner
A very simple higher order component can wrap any component in a div with a specific style, giving every wrapped component the same visual treatment without needing to add that sty…
Hooks
All 5 questionsHooks are special functions, like useState and useEffect, that let a function component use features such as state and lifecycle behavior, which used to only be available in class…
useState lets a function component remember a value between renders and gives you a function to update that value. Calling the update function tells React to re render the componen…
useReducer manages state using a function called a reducer, which decides how the state should change based on an action you send it. It becomes a better choice than useState when…
useMemo remembers the result of an expensive calculation and only recalculates it when one of its listed dependencies actually changes. This avoids repeating slow work on every sin…
Hooks must always be called in the exact same order on every render, so they should only be called at the top level of a component or a custom hook, never inside loops, conditions,…
Internationalization (i18n) in React
All 5 questionsInternationalization, often shortened to i18n, means building an app so it can easily show text in different languages for different users around the world. Instead of hardcoding E…
react i18next lets you organize translated text into separate files for each language, and provides a useTranslation hook that gives your components a simple function to look up th…
Different languages have very different rules for plurals, some with more than just a singular and plural form. Translation libraries like react i18next let you define separate tra…
You set the direction attribute on your page, usually to rtl for right to left languages, which flips the layout so text and elements read from right to left instead of left to rig…
You store the currently selected language in state or context, and a select dropdown lets the user change that value. Whenever the language changes, the translation library updates…
Performance (memo/useMemo)
All 5 questionsReact.memo wraps a component and tells React to skip re rendering it if its props have not actually changed since the last render. This is useful for components that render often b…
useCallback remembers a function itself between renders, so the same function reference is reused instead of creating a brand new one every time. useMemo remembers the result of a…
- How would you use the React Profiler to find which components are causing performance problems? Advanced
The React DevTools Profiler tab lets you record how long each component takes to render during an interaction, showing a visual chart of exactly which components re rendered and ho…
Every use of useMemo or React.memo has a small cost of its own, since React still needs to check whether the dependencies changed. Adding them everywhere, especially to simple, fas…
Imagine a component that sorts a very large list of items every time it renders. If the list itself has not changed, sorting it again on every render wastes time. Wrapping that sor…
Portals & Fragments
All 5 questionsA Portal lets you render a component's content into a different part of the actual page structure, outside of its normal parent element, while it still behaves like a normal part o…
Even though a Portal's content is placed elsewhere in the actual HTML, React still treats click and other events as if they bubble up through the normal component tree, not through…
A Fragment lets you group several elements together without adding an extra wrapping element to the actual page. This is useful when adding a div would break your CSS layout, such…
When mapping over a list and returning more than one element per item, you cannot use the short Fragment syntax if you also need to add a key, since the shorthand does not accept a…
- How would you build a tooltip using a Portal so it always appears above everything else on the page? Advanced
A tooltip rendered inside a deeply nested component can sometimes get visually cut off by a parent element with hidden overflow. Rendering the tooltip through a Portal, directly at…
Props & State
All 5 questionsProps are values passed into a component from its parent, and a component cannot change its own props directly. State is data that a component manages internally and can change ove…
You pass data as props, which look like HTML attributes when writing JSX. The child component receives these values as a single object, usually written using destructuring to pull…
- Why is state considered the single source of truth for data that changes in a React component? Intermediate
Keeping data in state rather than scattered across variables or the actual DOM ensures React always knows the current, correct value, and can reliably re render the screen to match…
Lifting state up means moving a piece of state from a child component up to their closest shared parent, so multiple sibling components can read and update the same data. This is n…
You can use default parameter syntax directly when destructuring props inside the function's parameter list, giving a fallback value that is used automatically whenever that specif…
React DevTools & Debugging
All 5 questionsReact DevTools is a free browser extension available for Chrome and Firefox that adds two new tabs to your browser's developer tools, letting you inspect the component tree, view c…
- How do you use the Components tab in React DevTools to inspect a component's current state? Intermediate
You click on any component shown in the tree on the left, and a panel on the right shows its current props, state, and hooks with their live values. You can even edit these values…
React DevTools has a setting to highlight updates when components re render, showing a colored outline flash around any component that just re rendered. The Profiler tab can also s…
Common causes include mutating an array or object directly instead of creating a new one, which React does not detect as a real change, or a missing dependency in a useEffect or us…
Read the error message carefully from top to bottom, since React error messages usually include the exact component name and often a helpful stack trace showing where the problem s…
Refs, useRef & forwardRef
All 5 questionsA ref gives you a way to directly access an actual DOM element or to store a value that does not need to cause a re render when it changes. Common uses include focusing an input fi…
Updating a value with useState causes the component to re render so the screen reflects the new value. Updating a ref's value using useRef does not cause any re render at all, maki…
By default, a ref you attach to a custom component does not automatically reach the actual DOM element inside it, since refs only work directly on native HTML elements like input o…
You can store the current prop value inside a ref after each render, using useEffect, so that the next time the component renders, the ref still holds the value from before the upd…
useRef is meant for function components and keeps the same ref object across every render, which is almost always what you want. createRef is the older approach used inside class c…
Render Props Pattern
All 5 questions- What is the render props pattern in React? Intermediate
The render props pattern means passing a function as a prop to a component, and that component calls the function to decide what to actually display, often passing some internal da…
You move the shared logic, like tracking state or subscribing to something, directly inside a custom hook, and return whatever data the component needs. The component using the hoo…
- What is a common naming alternative to render props, using children as a function instead? Intermediate
Instead of a named prop called render, some components accept children as a function directly, which reads a bit more naturally in JSX since it looks like normal nested content, ev…
A component that tracks whether the browser window is online or offline could use render props, letting different parts of an app show that information in completely different ways…
Nesting several render props components inside each other can create deeply indented, harder to read code, sometimes called callback nesting, similar to the wrapper hell problem se…
Routing
All 5 questionsClient side routing lets a user navigate between different pages of a single page app without the browser actually reloading the page from the server every single time. React Route…
Instead of a regular HTML anchor tag, which would cause a full page reload, React Router provides a Link component that changes the current page smoothly using client side routing,…
- How do you read a dynamic value from the URL, such as a product id, using React Router? Intermediate
You define a route with a colon before a name, like colon id, and React Router's useParams hook then gives you access to that specific value from the current web address inside you…
You create a wrapper component that checks whether the user is logged in, and either renders the protected page or redirects them to a login page instead, using the Navigate compon…
React Router provides a useNavigate hook that gives you a function to change the current page directly from your code, instead of relying on the user clicking a link, which is usef…
Security in React (XSS & dangerouslySetInnerHTML)
All 5 questions- What is cross site scripting, often called XSS, and how does React protect against it by default? Beginner
Cross site scripting happens when an attacker manages to inject malicious code into a page, which then runs in another user's browser, often stealing information or performing unwa…
dangerouslySetInnerHTML lets you insert raw HTML directly into a component, bypassing React's normal automatic protection against cross site scripting. The name is a clear warning…
You use a trusted sanitization library, like DOMPurify, to clean the HTML first, removing any dangerous scripts or unsafe attributes, before ever passing the result into dangerousl…
Data kept only in memory disappears the moment the page reloads, but more importantly, any sensitive token accessible to your app's JavaScript can potentially be read by malicious…
- Why is it risky to build a link's web address directly from user input without checking it first? Beginner
A malicious user could enter something like javascript colon followed by harmful code instead of a normal web address, and if that value is used directly as a link's destination, c…
Server Actions & Data Mutations
All 5 questionsA server action is a function that runs directly on the server but can be called from a component as if it were a normal function, letting a form submit data and update a database…
- How does the useFormStatus hook help show loading feedback while a server action is running? Advanced
useFormStatus gives you access to information about the nearest parent form's current submission state, including a pending flag, letting you disable a submit button or show a load…
This hook connects a form to a server action and also gives you access to the most recent result returned by that action, such as a validation error message, letting you display fe…
- How would you refresh data shown on a page after a server action successfully changes something in the database? Intermediate
Frameworks that support server actions, like Next.js, provide a function such as revalidatePath, which tells the framework that data for a specific page is now outdated and should…
A newsletter signup form can call a server action directly when submitted, which saves the visitor's email address to a database on the server, without the developer needing to wri…
Server Components
All 5 questionsA Server Component renders entirely on the server, sending only the finished result to the browser instead of the actual JavaScript code needed to run it. This means a Server Compo…
A Client Component runs in the browser and can use hooks, respond to clicks, and manage its own state, just like components worked before Server Components existed. You mark a file…
Server Components can render Client Components as children, letting a mostly static page include small interactive pieces exactly where needed. However, a Server Component cannot b…
Server Components reduce the amount of JavaScript sent to the browser, since their actual code never needs to run on the client at all. They also let you safely access databases an…
Next.js, one of the most widely used React frameworks, added first class support for Server Components starting with its app router, making Server Components the default for every…
Server-Side Rendering (SSR) & Next.js
All 5 questionsServer side rendering means generating the full HTML for a page on the server before sending it to the browser, instead of sending an almost empty page and building everything with…
Hydration is the process where React takes the already rendered HTML sent from the server and attaches the necessary JavaScript behavior to it in the browser, making buttons clicka…
The pages router, Next.js's original approach, defines each route as a file inside a pages folder, and every page is rendered on the client by default unless configured otherwise.…
Inside a Server Component, you can simply use await directly in the component function to fetch data, since the code runs on the server, without needing useEffect, useState, or a l…
Next.js provides file based routing, meaning creating a new file automatically creates a new page, built in support for server side rendering and static generation, automatic code…
State Management
All 5 questionsState management refers to how an app organizes and shares data that changes over time, such as the current logged in user, items in a shopping cart, or a form's values. Small apps…
Local state belongs to a single component and is not needed anywhere else, such as whether a specific dropdown is open. Global state is data that many different, often unrelated co…
- How do you decide between using Context, a state management library, or simply lifting state up? Advanced
Lifting state up works well when only a few closely related components need to share data. Context works well for moderately shared data that does not change extremely often, like…
- What does it mean for state to be normalized, and why does this matter for larger apps? Intermediate
Normalized state stores related data, like users and their posts, as separate flat collections referenced by id, instead of deeply nesting one inside the other. This avoids duplica…
If the same piece of data needs to be passed through many layers of components that do not actually use it themselves, often called prop drilling, or if unrelated parts of an app f…
State Management Libraries (Redux, Zustand & Recoil)
All 5 questionsRedux keeps all of an app's shared state in one single central store, and the only way to change that state is by sending a plain object called an action to a function called a red…
Zustand lets you create a shared store using a simple function, without needing separate actions, reducers, or a Provider wrapping your app. Components read exactly the pieces of s…
Recoil breaks shared state into small, independent pieces called atoms, and each component subscribes only to the specific atoms it actually needs, rather than the entire store lik…
- How do middleware, such as Redux Thunk, help handle asynchronous operations like API calls in Redux? Intermediate
Regular Redux actions are plain objects and cannot directly contain asynchronous logic like a fetch call. Middleware like Redux Thunk lets you dispatch a function instead of a plai…
- How do you decide which state management library, if any, is right for a specific React project? Beginner
For most small to medium apps, useState and Context together are often perfectly sufficient. Zustand is a good lightweight choice when a bit more shared global state organization i…
Static Site Generation (SSG) & Hydration
All 5 questionsStatic site generation builds the HTML for every page in advance, at build time, before any visitor even requests the page, then simply serves those already built files instantly.…
- What is incremental static regeneration and how does it solve the problem of static content becoming outdated? Intermediate
Incremental static regeneration lets a statically generated page be automatically rebuilt in the background after a set amount of time, without needing to rebuild the entire site.…
- What is hydration mismatch, and what commonly causes this error in a React app using server rendering? Intermediate
A hydration mismatch happens when the actual HTML sent from the server does not exactly match what React expects to render in the browser during hydration, often caused by renderin…
- How would you decide between static site generation and server side rendering for a specific page? Advanced
Choose static site generation for content that is the same for every visitor and does not change extremely often, like a blog post or a marketing page, since it can be built once a…
Since the HTML for a statically generated page was already built ahead of time, the server, or often a content delivery network located physically close to the visitor, can send th…
Strict Mode & Concurrent Features
All 5 questionsStrict Mode is a development only tool that helps find potential problems in your app early, before they cause real bugs. It does not render anything visible itself, but it intenti…
- Why does Strict Mode call component functions and certain effects twice during development? Intermediate
This intentional double calling helps reveal components or effects that are not properly written to handle being interrupted or repeated, which matters for React's newer concurrent…
Concurrent features let React prepare more than one version of the user interface at the same time, pausing and resuming work as needed, so the app stays responsive even while hand…
Automatic batching means React groups multiple state updates that happen close together into a single re render, instead of re rendering separately for each one. This reduces unnec…
Strict Mode is generally recommended to stay enabled throughout an entire project's development, since it continues to help catch new problems as the codebase grows and changes ove…
Styling in React (CSS Modules, Styled Components & Tailwind)
All 5 questionsA CSS Module is a regular CSS file where every class name is automatically made unique behind the scenes during the build process, so a class name like button used in one component…
Styled components lets you write actual CSS inside a special template literal attached to a component definition, creating a real React component with those styles automatically ap…
- What is Tailwind CSS and how does its approach differ from writing traditional custom CSS? Intermediate
Tailwind CSS provides many small, single purpose utility classes, like flex, text center, or bg blue 500, that you combine directly in your JSX to build a design, instead of writin…
You build the class name string dynamically based on your current state or props, often using a small helper library like clsx or classnames to make combining multiple conditional…
Plain CSS or CSS Modules work well for teams that already know CSS well and prefer keeping styles in separate files. Styled components fit teams that want styles and component logi…
Suspense & Concurrent Rendering
All 5 questionsSuspense lets a component tell React that it is not ready yet, such as while data is still loading, and React shows a fallback, like a loading spinner, until it is ready. This give…
React.lazy marks a component to be loaded only when it is actually needed, and Suspense provides the fallback content to show while that component's code is still downloading in th…
Certain data fetching libraries and frameworks, including newer patterns in React itself, let a component suspend rendering while data is still being fetched, letting the same Susp…
Instead of wrapping an entire page in one single Suspense boundary, you can place a separate Suspense boundary around each individual section, letting each part of the page finish…
A good fallback usually matches the general size and shape of the content it is replacing, such as a skeleton placeholder that resembles the layout of the actual content, rather th…
Testing
All 5 questionsReact Testing Library encourages testing a component the way an actual user would interact with it, such as finding a button by its visible text and clicking it, rather than checki…
You typically mock the actual fetch function or API call so your test does not depend on a real network request, providing fake sample data instead, then use React Testing Library'…
Snapshot testing saves a recorded version of a component's rendered output the first time a test runs, and future test runs compare the current output against that saved snapshot,…
Tools like Cypress or Playwright run your actual app in a real browser and simulate a real user's actions across multiple pages, such as typing into a login form, clicking submit,…
A unit test checks a small, isolated piece of logic, like a single function that formats a price, completely on its own. A component test renders an actual React component and chec…
TypeScript with React
All 5 questionsTypeScript adds type checking to JavaScript, catching many common mistakes, like passing the wrong kind of value to a component, before the code even runs, right inside your code e…
TypeScript usually figures out the correct type automatically based on the initial value you give useState, but you can also specify the type explicitly inside angle brackets, whic…
React provides a built in type called ReactNode that covers anything that is valid to render, including text, numbers, elements, and arrays of elements, making it the correct type…
TypeScript generics let a component's prop types adapt to whatever specific data type is actually passed in, letting you write one flexible List component that works correctly and…
- How do you type an event handler function, such as a button's onClick handler, in TypeScript? Beginner
React provides specific event types, like React.MouseEvent, that describe exactly what information a given event handler receives, letting TypeScript check that you are using the e…
useReducer & Complex State Logic
All 5 questionsA reducer is a plain function that takes the current state and an action describing what happened, and returns the new state based on that action. It should never directly change t…
- How would you manage a multi step form's state using useReducer instead of several separate useState calls? Intermediate
A multi step form often has many related pieces of state, like the current step number and each field's value, that change together in predictable ways. useReducer lets you organiz…
- How would you combine useReducer with the Context API to share complex state across many components? Advanced
You create a reducer to manage the shared state and its update logic, then use Context to make both the current state and the dispatch function available to any component nested in…
An action object can include any additional properties beyond just its type, commonly called a payload, letting the reducer know exactly what data it needs to correctly compute the…
useReducer becomes a better fit when a component has several related pieces of state that often update together, or when the logic for updating state grows complicated enough that…
Virtual DOM & Reconciliation
All 5 questionsThe virtual DOM is a lightweight, plain JavaScript representation of what the actual page should look like, kept in memory by React. When state changes, React first updates this li…
- What is reconciliation in React, and how does it decide what actually needs to change on the screen? Intermediate
Reconciliation is the process React uses to compare the new virtual DOM against the previous one, figuring out the smallest set of actual changes needed to update the real page. Re…
React uses the key prop as a strong signal of identity for elements in a list or a set of siblings. If the key changes, React assumes it is looking at a genuinely different element…
When React compares the new virtual DOM to the old one and finds a completely different type of element or component in the same position, such as a div being replaced by a span, i…
Directly changing the real browser page is a relatively slow operation, since the browser has to recalculate layout and repaint the screen. By first figuring out the smallest neces…