LearnThatStack Ace your next interview
Frontend Development

React.

Start free Change topic Change

Practise React one question at a time. Answer out loud or in writing, get graded, and see exactly what you missed.

Try one question

What is the Virtual DOM and how does it work?

The answer

The Virtual DOM is an in-memory JavaScript representation of the Document Object Model (DOM), which React syncs with the real DOM.

When state changes, React takes four steps:

  1. React builds a new virtual DOM tree.
  2. React compares, or diffs, it with the previous tree.
  3. React works out the changes the real DOM needs.
  4. React applies only those changes to the real DOM.

This process is called reconciliation. The benefit is declarative code. You describe the UI, and React makes only the DOM writes it needs.

Example · what grading looks like
What are the differences between functional and class components?

“Functional components are just plain functions that take props and return JSX, so the syntax is a lot simpler, and they handle state and side effects through hooks like useState and useEffect. Class components extend React.Component, keep state in this.state, and use lifecycle methods like componentDidMount, so they're more verbose and you have to deal with this. I'd also say functional components tend to be a bit lighter and easier to test because there's less boilerplate around them.”

Knew it

They cover the core split: plain functions with hooks versus classes with this.state and lifecycle methods. To strengthen it, mention that error boundaries still require a class and that performance is about the same.

Missed: Does not say that error boundaries still require a class component.

Missed: Does not say function components are the preferred modern approach and classes are legacy. The 'a bit lighter' claim is vague, since raw performance is about the same.


Get your own answers graded

Sign up free. Your account comes with 50 credits for grading, and it remembers what you missed.

What it covers

All 103 questions

Each on its own page

JSX and rendering basics

How JSX turns into elements, how the virtual DOM works, and how to render fragments, conditions, lists with keys and portals.

10 questions

  1. What is the Virtual DOM and how does it work?
  2. What is JSX and why is it used in React?
  3. What's the difference between React elements and React components?
  4. What are the rules of JSX?
  5. What is React Fragment and when would you use it?
  6. How do you conditionally render elements in React?
  7. How do you render lists in React?
  8. What is the difference between React and ReactDOM? Pro
  9. What is the key prop and why is it important? Pro
  10. What are React Portals? Pro

Components, props and state

Function and class components, and how data moves through a tree: props down, callbacks up, and the problem of prop drilling.

8 questions

  1. What are the differences between functional and class components?
  2. How do you create a React component?
  3. What are props in React?
  4. What is state in React?
  5. What's the difference between props and state?
  6. What is lifting state up in React, and when do you need it? Pro
  7. How do you pass data from child to parent component? Pro
  8. What is prop drilling and how can you avoid it? Pro

Events and forms

Handling events with SyntheticEvents, passing arguments to handlers, controlled and uncontrolled inputs, form validation and drag and drop.

9 questions

  1. How do you handle events in React?
  2. How do you prevent default behavior in React events?
  3. How do you pass parameters to event handlers?
  4. What are controlled vs uncontrolled components? Pro
  5. What are SyntheticEvents in React? Pro
  6. How do you handle form validation in React? Pro
  7. How do you handle different form input types? Pro
  8. How do you handle forms with multiple inputs efficiently? Pro
  9. How do you implement drag and drop in React? Pro

Hooks, effects and lifecycle

The core hooks and their rules, custom hooks, useEffect and its dependencies, useLayoutEffect, and the class lifecycle methods they replace.

14 questions

  1. What is useState hook and how do you use it? Pro
  2. What are React Hooks? Pro
  3. What are React lifecycle methods? Pro
  4. What is componentDidMount and when is it used? Pro
  5. What is componentWillUnmount and when is it used? Pro
  6. What is useEffect hook and what are its use cases? Pro
  7. What's the difference between useEffect with and without dependencies? Pro
  8. What is useReducer hook and when should you use it? Pro
  9. What are the rules of Hooks? Pro
  10. What is useRef hook? Pro
  11. What are custom Hooks? Pro
  12. What is useId hook? Pro
  13. What is the difference between useLayoutEffect and useEffect? Pro
  14. What is a stale closure in React hooks, and how do you fix it? Pro

Context and state management

Sharing state with Context and when it gets slow, picking a state approach or library such as Redux, and persisting or undoing state.

8 questions

  1. What is the useContext hook and how do you use it? Pro
  2. What is React Context and when should you use it? Pro
  3. What are different ways to manage state in React? Pro
  4. When should you use external state management libraries? Pro
  5. How do you handle state persistence across page refreshes? Pro
  6. What is Redux and how does it work with React? Pro
  7. What are the performance implications of Context? Pro
  8. How do you implement undo/redo functionality? Pro

Routing, auth and security

Client-side routing with React Router, route parameters and protected routes, handling login and permissions, and common security risks like XSS.

6 questions

  1. What is React Router and how do you use it? Pro
  2. How do you handle route parameters in React Router? Pro
  3. How do you implement protected routes? Pro
  4. What's the difference between BrowserRouter and HashRouter? Pro
  5. What are common security concerns in React applications? Pro
  6. How do you handle authentication and authorization? Pro

Error handling and async data

Catching render errors with error boundaries, handling failed async requests, and keeping the UI responsive with optimistic updates.

4 questions

  1. What are Error Boundaries in React? Pro
  2. How do you handle errors in async operations? Pro
  3. How do you create Error Boundaries with Hooks? Pro
  4. How do you implement optimistic updates? Pro

Component design patterns

Ways to reuse logic and build flexible components: composition, HOCs, render props, compound components, providers, forwarded refs and state reducers.

9 questions

  1. What is the Container/Presentational component pattern? Pro
  2. What is the Provider pattern? Pro
  3. What is Component Composition and how does it compare to inheritance? Pro
  4. What are Higher-Order Components (HOCs)? Pro
  5. What is the Render Props pattern? Pro
  6. What is the Forwarding Refs pattern? Pro
  7. What are Compound Components? Pro
  8. What is the Observer pattern in React? Pro
  9. What is the State Reducer pattern? Pro

Testing React components

Testing components, state, effects, context, custom hooks, async API calls and complex user interactions with Jest and React Testing Library.

6 questions

  1. How do you test React components? Pro
  2. How do you test components with state and effects? Pro
  3. How do you test async operations and API calls? Pro
  4. How do you test components with Context? Pro
  5. How do you test custom hooks? Pro
  6. How do you test components with complex user interactions? Pro

Tooling, builds and deployment

Project setup tools such as Create React App and Vite, StrictMode, development and production builds, environment variables and ways to deploy.

5 questions

  1. What alternatives exist to Create React App? Pro
  2. What is the difference between development and production builds? Pro
  3. How do you handle environment variables in React? Pro
  4. What are some deployment strategies for React applications? Pro
  5. What is React.StrictMode? Pro

Performance optimization

Stopping unneeded re-renders with memo, useMemo and useCallback, splitting code, handling long lists and images, and measuring where time goes.

13 questions

  1. What is useMemo hook and when should you use it? Pro
  2. What is useCallback hook? Pro
  3. What is React.memo and when should you use it? Pro
  4. What is the difference between useMemo and React.memo? Pro
  5. What is React.lazy and Suspense? Pro
  6. What is code splitting in React? Pro
  7. How do you optimize images in React applications? Pro
  8. What are some common React performance optimization techniques? Pro
  9. What are the best practices for optimizing large lists? Pro
  10. How do you optimize React apps for production? Pro
  11. How do you implement infinite scrolling in React? Pro
  12. How do you measure React application performance? Pro
  13. What is the React Compiler? Pro

Concurrent and server rendering

How Fiber lets React pause and prioritize work, the concurrent hooks added in React 18, and rendering on the server with SSR, SSG and Server Components.

11 questions

  1. What is Server-Side Rendering (SSR) vs Client-Side Rendering (CSR)? Pro
  2. What is Static Site Generation (SSG)? Pro
  3. What are the new features in React 19? Pro
  4. What is hydration in React? Pro
  5. What are the new features in React 18? Pro
  6. What is React Fiber? Pro
  7. What are concurrent features in React? Pro
  8. What is useTransition hook? Pro
  9. What is useDeferredValue hook? Pro
  10. What is useSyncExternalStore hook? Pro
  11. What are React Server Components? Pro
Practice · Questions

All questions

Showing of 103
Beginner 22
01

What is the Virtual DOM and how does it work?

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

The Virtual DOM is an in-memory JavaScript representation of the Document Object Model (DOM), which React syncs with the real DOM.

When state changes, React takes four steps:

  1. React builds a new virtual DOM tree.
  2. React compares, or diffs, it with the previous tree.
  3. React works out the changes the real DOM needs.
  4. React applies only those changes to the real DOM.

This process is called reconciliation. The benefit is declarative code. You describe the UI, and React makes only the DOM writes it needs.

Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

02

What is JSX and why is it used in React?

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

JSX, short for JavaScript XML, is a syntax extension that lets you write HTML-like markup inside JavaScript. It makes components easier to read and write, and lets you mix JavaScript expressions into markup. JSX also gives better error messages and enables static type checking.

A compiler such as Babel turns JSX into function calls. The classic transform produces React.createElement() calls.

// JSX
const element = <h1>Hello, World!</h1>;

// Transpiled to
const element = React.createElement('h1', null, 'Hello, World!');

The new JSX transform, supported since React 17, calls react/jsx-runtime instead, so you can use JSX without importing React. React 19 requires it.

Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

03

What's the difference between React elements and React components?

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

A React element is a plain object describing what should appear on screen, while a React component is a function or class that returns elements. Elements are the smallest building blocks of a React app, and components are the reusable pieces that produce them.

const element = <h1>Hello, World!</h1>;

JSX like this creates an element. React never changes an element after it's created, so to show something different, React calls your components again and gets new elements.

// Function component
function Welcome(props) {
  return <h1>Hello, {props.name}</h1>;
}

// Class component
class Welcome extends React.Component {
  render() {
    return <h1>Hello, {this.props.name}</h1>;
  }
}

A component accepts inputs called props and can be reused anywhere. You write <Welcome name="Sara" /> to use it, and React calls Welcome with those props to get the element to render.

Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

04

What are the differences between functional and class components?

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

The main difference is how they handle state and lifecycle logic. A function component is a plain function that uses Hooks such as useState. A class component extends React.Component and uses this.state and lifecycle methods. Function components are the preferred approach in modern React, and classes are a legacy approach React still supports.

Function components have simpler syntax and are easier to test and debug. They skip some class overhead, like creating instances and binding handlers, but raw performance is about the same.

function MyComponent(props) {
  const [count, setCount] = useState(0);
  
  return <div>{count}</div>;
}

Class components are more verbose and return JSX from render(). They use lifecycle methods such as componentDidMount and have access to the this context.

class MyComponent extends React.Component {
  constructor(props) {
    super(props);
    this.state = { count: 0 };
  }
  
  render() {
    return <div>{this.state.count}</div>;
  }
}

Error boundaries still require a class, because there is no way to write one as a function component.

Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

05

How do you create a React component?

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

Write a JavaScript function that returns JSX, and give it a name that starts with a capital letter. React calls it with a props object, and you use it in JSX like an HTML tag, such as <Welcome name="Sara" />.

There are two main ways to write one:

  1. A function component, the recommended way. You can declare it with the function keyword or as an arrow function.
  2. A class component, which extends React.Component and returns JSX from render(). It's the older style, and React still supports it.
function Welcome(props) {
  return <h1>Hello, {props.name}!</h1>;
}

// Or using arrow function
const Welcome = (props) => {
  return <h1>Hello, {props.name}!</h1>;
};
class Welcome extends React.Component {
  render() {
    return <h1>Hello, {this.props.name}!</h1>;
  }
}
Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

06

What are the rules of JSX?

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

JSX needs a single parent element, camelCase attributes and closed tags, because it compiles to JavaScript rather than HTML. The key rules:

  1. A component must return a single parent element, or wrap its siblings in a React Fragment.
  2. Attributes use camelCase, so class becomes className and onclick becomes onClick.
  3. Every tag must close, and self-closing tags end with />.
  4. Curly braces embed JavaScript expressions, such as {variable} or {expression}.
  5. A boolean attribute can be written as disabled={true} or just disabled.
// Correct JSX
function MyComponent() {
  return (
    <div className="container">
      <img src="image.jpg" alt="Description" />
      <p>Count: {count}</p>
    </div>
  );
}
Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

07

What is React Fragment and when would you use it?

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

React Fragment lets you group multiple elements without adding an extra node to the DOM. It's useful when you need to return multiple elements from a component but don't want to wrap them in a div.

// Using React.Fragment
function MyComponent() {
  return (
    <React.Fragment>
      <h1>Title</h1>
      <p>Description</p>
    </React.Fragment>
  );
}

// Using short syntax
function MyComponent() {
  return (
    <>
      <h1>Title</h1>
      <p>Description</p>
    </>
  );
}
Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

08

How do you conditionally render elements in React?

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

Use plain JavaScript to choose what to render. There are three common patterns.

  1. A ternary, condition ? <A /> : <B />, picks between two elements.
function Greeting({ isLoggedIn }) {
  return (
    <div>
      {isLoggedIn ? <h1>Welcome back!</h1> : <h1>Please log in.</h1>}
    </div>
  );
}
  1. Logical AND, condition && <A />, renders an element or nothing.
function Notification({ hasMessages }) {
  return (
    <div>
      {hasMessages && <p>You have new messages!</p>}
    </div>
  );
}
  1. An if and else statement with early returns handles bigger branches.
function UserStatus({ user }) {
  if (user.isAdmin) {
    return <AdminPanel />;
  } else if (user.isLoggedIn) {
    return <UserPanel />;
  } else {
    return <LoginForm />;
  }
}

Keep the left side of && a boolean. If it's the number 0, React renders 0 instead of nothing.

Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

09

How do you render lists in React?

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

Call map() on the array and return a JSX element for each item. Give each element a key prop that is unique among its siblings.

function TodoList({ todos }) {
  return (
    <ul>
      {todos.map(todo => (
        <li key={todo.id}>
          {todo.text}
        </li>
      ))}
    </ul>
  );
}

The key tells React which item each element belongs to. When the list changes, React uses the keys to see which items were added, removed or changed. It then updates only those and keeps each item's state, which improves performance during re-renders.

Use a stable ID from your data as the key. An array index breaks when items are inserted, removed or reordered, and a random key makes React recreate every item on each render.

Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

10

What are props in React?

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

Props, short for properties, are read-only inputs that a parent component passes to a child component. They let data flow down the component tree.

// Parent component
function App() {
  return <Welcome name="John" age={25} />;
}

// Child component
function Welcome(props) {
  return <h1>Hello, {props.name}! You are {props.age} years old.</h1>;
}

A child treats its props as immutable. It reads them to decide what to render and never changes them. A prop can be any JavaScript value, such as a string, a number or an object. Function props work too, which is how a child tells its parent that something happened.

Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

11

What is state in React?

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

State is data React keeps for a component, and it can change over the component's lifetime. When state changes, React re-renders the component.

import { useState } from 'react';

function Counter() {
  const [count, setCount] = useState(0);
  
  return (
    <div>
      <p>Count: {count}</p>
      <button onClick={() => setCount(count + 1)}>
        Increment
      </button>
    </div>
  );
}

State is local to its component, and each copy of the component gets its own. It is mutable in the sense that it changes over time, but you never modify it directly. You call the setter, like setCount, and React re-renders with the new value.

Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

12

What's the difference between props and state?

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

Props are inputs a component receives from its parent, and state is data a component owns and changes itself. Props flow down and are read-only, while state is the component's own memory.

Props State
Read-only Mutable
Passed from parent Local to component
Cannot be changed by component Can be changed by component
External data Internal data
Functional parameters Component memory

A component can't change its own props. When the parent passes new props, the component re-renders with them. State changes through the component's setter, like setCount, and each change also triggers a re-render. The two often meet, because a parent's state becomes a child's props.

Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

13

How do you handle events in React?

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

Pass a function as a camelCase prop on the element, like onClick={handleClick}. React calls it with an event object when the event fires, such as a click or a key press.

function Button() {
  const handleClick = (event) => {
    event.preventDefault();
    console.log('Button clicked!');
    console.log('Event type:', event.type);
  };
  
  return (
    <button onClick={handleClick}>
      Click me
    </button>
  );
}

Pass the function itself, not a call. onClick={handleClick()} would run the handler during rendering instead of on click.

The event object is a SyntheticEvent, React's wrapper around the native browser event. It behaves the same across browsers and has the usual methods and properties, such as preventDefault() and type.

Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

14

How do you prevent default behavior in React events?

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

Call preventDefault() on the event object that React passes to your handler. The usual case is a form, where it stops the browser from submitting and reloading the page, so your code can handle the data instead.

function Form() {
  const handleSubmit = (event) => {
    event.preventDefault(); // Prevents form from submitting
    console.log('Form submitted');
  };
  
  return (
    <form onSubmit={handleSubmit}>
      <input type="text" />
      <button type="submit">Submit</button>
    </form>
  );
}

Returning false from the handler doesn't work in React the way it does in plain HTML. You must call preventDefault() explicitly. To stop the event from bubbling up to parent elements, call stopPropagation(), which is a different thing.

Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

15

How do you pass parameters to event handlers?

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

Wrap the handler in an arrow function inside the JSX, and call your handler with the values you need. React calls the arrow on click, and the arrow calls your handler with the item's ID.

There are two common ways to do it:

  1. An arrow function, like onClick={() => handleClick(item.id)}, puts the call and its arguments right in the JSX.
  2. The function's bind method pre-fills the arguments, as in handleClick.bind(null, item.id). React passes the event after them.
function ItemList({ items }) {
  const handleClick = (id) => {
    console.log('Clicked item:', id);
  };
  
  return (
    <div>
      {items.map(item => (
        <button key={item.id} onClick={() => handleClick(item.id)}>
          {item.name}
        </button>
      ))}
    </div>
  );
}

To use the event as well, pass it along with (e) => handleClick(item.id, e). Both ways create a new function on every render. That only matters when the handler goes to a memoized child.

Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

16

What is useState hook and how do you use it?

Part of Pro Visual
17

What are controlled vs uncontrolled components?

Part of Pro
18

What is the difference between React and ReactDOM?

Part of Pro
19

What is lifting state up in React, and when do you need it?

Part of Pro
20

What are React Hooks?

Part of Pro
21

How do you pass data from child to parent component?

Part of Pro
22

What is the key prop and why is it important?

Part of Pro Visual
Intermediate 59
23

What is prop drilling and how can you avoid it?

Part of Pro Visual
24

What are SyntheticEvents in React?

Part of Pro
25

What are React lifecycle methods?

Part of Pro
26

What is componentDidMount and when is it used?

Part of Pro
27

What is componentWillUnmount and when is it used?

Part of Pro
28

What is useEffect hook and what are its use cases?

Part of Pro Visual
29

What's the difference between useEffect with and without dependencies?

Part of Pro
30

What is the useContext hook and how do you use it?

Part of Pro
31

What is useReducer hook and when should you use it?

Part of Pro
32

What are the rules of Hooks?

Part of Pro Visual
33

What is useMemo hook and when should you use it?

Part of Pro
34

What is useCallback hook?

Part of Pro
35

What is useRef hook?

Part of Pro
36

What are custom Hooks?

Part of Pro
37

What is React Context and when should you use it?

Part of Pro
38

What are different ways to manage state in React?

Part of Pro
39

When should you use external state management libraries?

Part of Pro
40

What is React.memo and when should you use it?

Part of Pro
41

What is the difference between useMemo and React.memo?

Part of Pro
42

What is React.lazy and Suspense?

Part of Pro
43

What is code splitting in React?

Part of Pro
44

What are Error Boundaries in React?

Part of Pro
45

How do you handle errors in async operations?

Part of Pro
46

What is React Router and how do you use it?

Part of Pro
47

How do you handle route parameters in React Router?

Part of Pro
48

How do you implement protected routes?

Part of Pro
49

What's the difference between BrowserRouter and HashRouter?

Part of Pro
50

How do you handle form validation in React?

Part of Pro
51

How do you handle different form input types?

Part of Pro
52

How do you test React components?

Part of Pro
53

How do you test components with state and effects?

Part of Pro
54

How do you test async operations and API calls?

Part of Pro
55

How do you test components with Context?

Part of Pro
56

What alternatives exist to Create React App?

Part of Pro
57

What is the difference between development and production builds?

Part of Pro
58

How do you handle environment variables in React?

Part of Pro
59

What are some deployment strategies for React applications?

Part of Pro
60

What is React.StrictMode?

Part of Pro
61

What are React Portals?

Part of Pro
62

How do you handle forms with multiple inputs efficiently?

Part of Pro
63

What is useId hook?

Part of Pro
64

What is the Container/Presentational component pattern?

Part of Pro
65

How do you optimize images in React applications?

Part of Pro
66

How do you test custom hooks?

Part of Pro
67

What is Server-Side Rendering (SSR) vs Client-Side Rendering (CSR)?

Part of Pro
68

What is Static Site Generation (SSG)?

Part of Pro
69

How do you handle state persistence across page refreshes?

Part of Pro
70

What is the difference between useLayoutEffect and useEffect?

Part of Pro Visual
71

What are the new features in React 19?

Part of Pro
72

What is hydration in React?

Part of Pro
73

What is Redux and how does it work with React?

Part of Pro
74

What is the Provider pattern?

Part of Pro
75

What are the new features in React 18?

Part of Pro
76

What is Component Composition and how does it compare to inheritance?

Part of Pro
77

What are Higher-Order Components (HOCs)?

Part of Pro
78

What is the Render Props pattern?

Part of Pro
79

What is the Forwarding Refs pattern?

Part of Pro
80

What are some common React performance optimization techniques?

Part of Pro
81

What are the best practices for optimizing large lists?

Part of Pro
Expert 22
82

What are the performance implications of Context?

Part of Pro Visual
83

How do you create Error Boundaries with Hooks?

Part of Pro
84

What are Compound Components?

Part of Pro
85

How do you optimize React apps for production?

Part of Pro
86

What is React Fiber?

Part of Pro
87

What are concurrent features in React?

Part of Pro
88

How do you implement drag and drop in React?

Part of Pro
89

How do you implement infinite scrolling in React?

Part of Pro Visual
90

What is useTransition hook?

Part of Pro Visual
91

What is useDeferredValue hook?

Part of Pro Visual
92

What is useSyncExternalStore hook?

Part of Pro Visual
93

What is the Observer pattern in React?

Part of Pro
94

What is the State Reducer pattern?

Part of Pro
95

How do you measure React application performance?

Part of Pro
96

How do you implement undo/redo functionality?

Part of Pro Visual
97

How do you implement optimistic updates?

Part of Pro Visual
98

What are common security concerns in React applications?

Part of Pro
99

How do you handle authentication and authorization?

Part of Pro
100

How do you test components with complex user interactions?

Part of Pro
101

What are React Server Components?

Part of Pro Visual
102

What is the React Compiler?

Part of Pro
103

What is a stale closure in React hooks, and how do you fix it?

Part of Pro Visual

No matches

Try a different filter or search term.

Know someone prepping for React? Send them this set.
Quick recap

React in pictures.

A quick recap of React in 33 short animated pictures, one idea at a time. About 8 min to get the whole topic back in your head before you walk in. Pause any picture, slow it down, or step through it.

Pro The first chapter is free to play. The other 28 pictures come with Pro.

Get Pro · $10/mo
Pro · $10/mo

88 of 103 React answers are in Pro.

Full answers, code samples, and AI explanations that go simpler or deeper. Cancel anytime.

  • Full answers + code
  • AI explanations, simpler or deeper
  • 1,000 AI credits / month
  • Cancel anytime

Change topic

Pick a different technology or stack. Your current topic stays put until you choose a new one.

Technologies
No technologies match “”.
Cross-cutting topics
No topics match “”.
By role
Stacks & frameworks

MEAN

MongoDB, Express, Angular, Node.js

MERN

MongoDB, Express, React, Node.js

LAMP

Linux, Apache, MySQL, PHP

Django

Python Full-Stack Development

Ruby on Rails

Convention over Configuration

Serverless on AWS

Serverless Architecture on AWS

Flutter Mobile

Flutter Cross-Platform Mobile Development

Spring Boot

Enterprise Java Development

.NET

Microsoft Ecosystem

Vue

Vue.js, Vite, TypeScript, Tailwind, Node.js

Go Backend

Golang, gRPC, PostgreSQL, Redis, RabbitMQ

FastAPI

Python, FastAPI, SQLAlchemy, PostgreSQL

React Native

React, TypeScript, Redux, Firebase

iOS Native

Swift, SwiftUI, UIKit, Firebase

Android Native

Java, Jetpack Compose, Firebase

DevOps / Platform

Docker, Kubernetes, Terraform, CI/CD

AI Engineer

LLMs, RAG, Agents, Evals

AI-Powered Developer

Claude Code, Copilot, Agentic Workflows

Core SWE Interview Prep

Data structures, algorithms, OS, concurrency, networking, git