🌍 The Odin Project · flashcards

The Odin Project React Flashcards

49 question-and-answer cards covering React as it is examined in The Odin Project. 24 of them are printed below, taken from across the deck — no signup, no paywall on the preview.

49Cards in deck
24Free preview
24Syllabus topics
~239Chars per answer
FreePrice

24 sample cards from the React deck

Sampled from the end of the deck, so these are different cards from the ones shown on the syllabus page.

  1. Why should you never mutate state directly in React?

    React compares state references to decide whether to re-render; mutating an object or array in place keeps the same reference, so React may not detect the change. Always call the setter with a new value, e.g. a copied object ({ ...obj, key: val }) or array ([...arr, item]).

  2. What does it mean that state updates are asynchronous and that renders capture a 'snapshot' of state?

    Calling a setter does not change the state variable in the currently running code; it schedules a re-render. Each render's functions see the state values from the render they were created in, so reading state right after setting it still gives the old value.

  3. What is an updater function in setState, and when should you use it?

    Passing a function to the setter, e.g. setCount(prev => prev + 1), makes React compute the new state from the latest pending state. Use it when the new state depends on the previous state, especially for multiple updates in one event handler.

  4. What is state batching in React?

    React groups multiple state updates that occur in the same event handler (and, since React 18, in promises and timeouts too) into a single re-render for performance, instead of re-rendering after each setter call.

  5. What triggers a React component to re-render?

    A change to its own state (via a setter), a re-render of its parent (which re-renders children by default), or a change in context it consumes. Props changing is a consequence of the parent re-rendering.

  6. What does 'lifting state up' mean?

    Moving shared state to the closest common ancestor of the components that need it. The ancestor passes the state down as props and passes setter callbacks so children can update it, keeping a single source of truth.

  7. What is a controlled component (controlled input)?

    A form element whose value is driven by React state: the input's value prop is set from state and its onChange handler updates that state, making React the single source of truth for the input's contents.

  8. What is a side effect in React, and which hook handles them?

    Any operation that reaches outside the rendering calculation — fetching data, timers, subscriptions, directly manipulating the DOM. The useEffect hook runs such code after the component renders.

  9. Explain the three parts of useEffect(callback, dependencies).

    The callback runs after render and contains the effect; it may return a cleanup function that runs before the effect re-runs and when the component unmounts; the dependency array controls when the effect re-runs (only when a listed value changes).

  10. How does the useEffect dependency array change when the effect runs?

    No array: the effect runs after every render. Empty array []: it runs only once after the initial mount (plus cleanup on unmount). Array with values [a, b]: it runs after mount and whenever any listed value changes.

  11. When does a useEffect cleanup function run, and give a typical use case.

    It runs before the effect executes again and when the component unmounts. Typical uses: clearing intervals/timeouts (clearInterval), removing event listeners, or aborting/cancelling subscriptions and fetches to prevent memory leaks.

  12. When should you NOT use useEffect?

    When a value can be computed from existing props/state during render (derive it instead), when responding to a user event (put the logic in the event handler), or to 'sync' state to other state. Effects are for synchronizing with external systems only.

  13. In the CV Application project pattern, how is switching between edit mode and display mode implemented?

    With a boolean piece of state (e.g. isEditing). Conditional rendering shows a form with controlled inputs when true and a read-only display of the submitted data when false; submitting the form updates state and flips the flag.

  14. In the Memory Card project, what causes the cards to re-shuffle and how is the score tracked?

    Clicking a card updates state (e.g. a list of already-clicked card IDs), which triggers a re-render that shuffles the card array. If the clicked card is already in the list, the current score resets and best score is updated; otherwise the score increments.

  15. How do you define a class-based React component?

    Create a class that extends React.Component with a render() method returning JSX. State is initialized in the constructor (after calling super(props)) as this.state, and updated with this.setState(); props are accessed via this.props.

  16. Why do class component event handlers often need bind (or arrow functions)?

    When a method is passed as a callback, it loses its 'this' binding, so this.setState would be undefined. Fix it by binding in the constructor (this.handleClick = this.handleClick.bind(this)) or defining the handler as a class-field arrow function.

  17. Name the three main lifecycle phases of a class component and their key methods.

    Mounting: constructor → render → componentDidMount. Updating (props or state change): render → componentDidUpdate. Unmounting: componentWillUnmount, used for cleanup like removing listeners or timers.

  18. How does useEffect map onto class lifecycle methods?

    useEffect with [] ≈ componentDidMount; useEffect with dependencies ≈ componentDidUpdate for those values; the effect's returned cleanup function ≈ componentWillUnmount. One hook can replace all three.

  19. Which libraries does The Odin Project use for React testing, and what does each do?

    Vitest (or Jest) as the test runner/assertion framework, React Testing Library (@testing-library/react) to render components and query the DOM as a user would, and @testing-library/user-event to simulate realistic user interactions like clicks and typing.

  20. In React Testing Library, what is the difference between getBy, queryBy, and findBy queries?

    getBy* throws an error if no match is found (use when the element should exist); queryBy* returns null instead of throwing (use to assert absence); findBy* returns a promise and waits for the element (use for elements that appear asynchronously).

  21. Why does React Testing Library recommend queries like getByRole over test IDs or CSS selectors?

    Querying by accessible role, label, or text tests the component the way users (and assistive technology) experience it, making tests more robust to implementation changes and encouraging accessible markup. Test IDs are a last resort.

  22. What is a mock function in testing, and why mock callback props?

    A fake function (e.g. vi.fn() or jest.fn()) that records how it was called. Passing it as a callback prop lets you assert the component invoked it correctly (toHaveBeenCalled, call counts, arguments) without running real logic — isolating the component under test.

  23. What is PropTypes and how do you declare a required string prop?

    A runtime type-checking library (the prop-types package) for component props that logs console warnings in development when props have wrong types. Declare with: MyComponent.propTypes = { name: PropTypes.string.isRequired }. Non-required props can get fallbacks via defaultProps or default parameters.

  24. What are the core building blocks of React Router for client-side routing?

    createBrowserRouter (defines an array of { path, element } route objects), RouterProvider (supplies the router to the app), <Link to="..."> for navigation without full page reloads, <Outlet /> to render child routes inside a parent layout, useParams to read dynamic URL segments like :id, and errorElement for unmatched/error routes.

What this deck covers

The React deck follows the The Odin Project React syllabus — 6 chapters and 24 topics — so questions land on material that is genuinely examinable rather than trivia around it. That works out to roughly 8.2 cards per chapter.

Answers are written to be recallable, not just readable — averaging about 239 characters, which is long enough to carry the reasoning and short enough to say out loud.

A deck like this earns its keep on the second and third pass. Read the syllabus first so you know the shape of the subject, then use the cards to find the specific facts that have not stuck.

React flashcards FAQ

How many React flashcards are in this The Odin Project deck?

49 cards. This page previews 24 of them, sampled evenly across the deck so you can judge the difficulty before installing anything.

Are these The Odin Project flashcards free?

Yes. The preview here is free to read with no signup, and the full 49-card deck is free inside the Examius app.

What do the React cards cover?

They follow the The Odin Project React syllabus — 6 chapters and 24 topics — so the questions track what is actually examinable.

How should I use these flashcards?

Read the syllabus first so you know the shape of the subject, then drill the deck. Examius schedules each card with spaced repetition, so cards you keep missing come back sooner and ones you know drift further apart.