Advertisement

Information Technology

React Interview Questions & Answers

Meta JavaScript component library for managing complex web interface views.

41topics 205questions last updated
Advertisement

Accessibility (a11y) in React

All 5 questions
  1. Accessibility 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…

  2. 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…

  3. 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…

  4. 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…

  5. 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 questions
  1. Framer 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…

  2. 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…

  3. 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…

  4. 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…

  5. 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 questions
  1. A 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…

  2. 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…

  3. 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…

  4. 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…

  5. 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 questions
  1. A 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…

  2. 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,…

  3. Error boundaries need two special lifecycle methods, getDerivedStateFromError and componentDidCatch, which are only available on class components. There is currently no hook versio…

  4. 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…

  5. 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 questions
  1. Code 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,…

  2. 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…

  3. 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…

  4. 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…

  5. 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 questions
  1. Component composition means building complex user interfaces by combining small, simple components together, instead of writing one giant component that does everything. This makes…

  2. 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…

  3. 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…

  4. 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…

  5. 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 questions
  1. JSX 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…

  2. 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…

  3. 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…

  4. 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…

  5. 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 questions
  1. useTransition 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…

  2. 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…

  3. 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…

  4. 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…

  5. 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 questions
  1. You 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…

  2. 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…

  3. 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…

  4. 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…

  5. 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 questions
  1. Context 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…

  2. 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…

  3. 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…

  4. 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…

  5. 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 questions
  1. A 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…

  2. 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…

  3. 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…

  4. 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…

  5. 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 questions
  1. Fetching 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…

  2. 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…

  3. 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…

  4. 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…

  5. 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 questions
  1. A 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…

  2. 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…

  3. 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.…

  4. 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…

  5. 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 questions
  1. This 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…

  2. 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…

  3. 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…

  4. 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…

  5. 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 questions
  1. useEffect 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…

  2. 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…

  3. 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…

  4. 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…

  5. 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 questions
  1. An 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…

  2. 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…

  3. 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…

  4. 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…

  5. 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 questions
  1. A 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…

  2. 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…

  3. 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…

  4. 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…

  5. 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
  1. 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…

  2. 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…

  3. 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…

  4. 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…

  5. 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…

  1. Hooks 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…

  2. 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…

  3. 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…

  4. 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…

  5. 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 questions
  1. Internationalization, 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…

  2. 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…

  3. 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…

  4. 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…

  5. 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 questions
  1. React.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…

  2. 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…

  3. 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…

  4. 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…

  5. 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 questions
  1. A 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…

  2. 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…

  3. 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…

  4. 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…

  5. 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 questions
  1. Props 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…

  2. 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…

  3. 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…

  4. 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…

  5. 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 questions
  1. React 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…

  2. 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…

  3. 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…

  4. 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…

  5. 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 questions
  1. A 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…

  2. 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…

  3. 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…

  4. 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…

  5. 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
  1. 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…

  2. 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…

  3. 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…

  4. 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…

  5. 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…

  1. Client 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…

  2. 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,…

  3. 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…

  4. 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…

  5. 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
  1. 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…

  2. 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…

  3. 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…

  4. 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…

  5. 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 questions
  1. A 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…

  2. 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…

  3. 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…

  4. 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…

  5. 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 questions
  1. A 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…

  2. 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…

  3. 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…

  4. 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…

  5. 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 questions
  1. Server 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…

  2. 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…

  3. 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.…

  4. 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…

  5. 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 questions
  1. State 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…

  2. 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…

  3. 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…

  4. 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…

  5. 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 questions
  1. Redux 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…

  2. 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…

  3. 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…

  4. 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…

  5. 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 questions
  1. Static 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.…

  2. 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.…

  3. 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…

  4. 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…

  5. 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 questions
  1. Strict 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…

  2. 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…

  3. 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…

  4. 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…

  5. 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 questions
  1. A 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…

  2. 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…

  3. 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…

  4. 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…

  5. 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 questions
  1. Suspense 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…

  2. 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…

  3. 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…

  4. 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…

  5. 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…

  1. React 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…

  2. 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'…

  3. 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,…

  4. 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,…

  5. 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 questions
  1. TypeScript 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…

  2. 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…

  3. 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…

  4. 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…

  5. 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 questions
  1. A 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…

  2. 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…

  3. 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…

  4. 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…

  5. 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 questions
  1. The 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…

  2. 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…

  3. 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…

  4. 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…

  5. 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…