Frontend School
DashboardProblemsLearnPracticeMock InterviewReportsStatsBuy Credits
DashboardProblemsLearnPracticeMock Interview
Frontend System Design Roadmap
  1. 1.HTTP/1.1 vs HTTP/2 vs HTTP/3 (QUIC)
  2. 2.TCP and TLS Handshakes: Connection Setup Costs
  3. 3.Browser Network Stack and Connection Pooling
  4. 4.GET vs POST and Idempotency in HTTP
  5. 5.The Critical Rendering Path (CRP)
  6. 6.DOM, CSSOM and the Render Tree
  7. 7.Layout, Paint and Compositing
  8. 8.Reflows and Repaints Explained
  9. 9.Event Loop: Call Stack, Task and Microtask Queues
  10. 10.Async JavaScript: Promises and async/await
  11. 11.Web Workers: Multi-threading in the Browser
  12. 12.Browser Storage: Cookies, Web Storage, IndexedDB
  13. 13.Client-Side Storage: Limits and Security Risks
  14. 14.Choosing the Right Client-Side Storage
  15. 15.HTTP Caching: Cache-Control, ETag, Last-Modified
  16. 16.Browser-Level Caching Mechanisms
  17. 17.Cache Invalidation for Frontend Apps
  18. 18.Structuring a Large Single-Page App
  19. 19.Component-Based Architecture Principles
  20. 20.Props, State and Component Lifecycle
  21. 21.Module Bundling Basics
  22. 22.Core Web Vitals: LCP, INP and CLS
  23. 23.FCP and Time to Interactive (TTI) Explained
  24. 24.Measuring Performance: Lighthouse and WebPageTest
  25. 25.Asset Compression and Minification Basics
  26. 26.What Is a CDN and How Does It Work?
  27. 27.CDN Benefits: Latency, Availability, Offload
  28. 28.CDN Cache Behavior and Invalidation
  29. 29.Global State vs Local Component State
  30. 30.State Patterns: Redux, Zustand and Context
  31. 31.Data Fetching: React Query and SWR
  32. 32.Immutable Data in Frontend State
  33. 33.SSR vs CSR: Rendering Trade-offs
  34. 34.Hydration and Time to First Byte (TTFB)
  35. 35.Static Site Generation (SSG) for Speed and SEO
  36. 36.Incremental Static Regeneration (ISR)
  37. 37.Micro-Frontends: Core Principles
  38. 38.Micro-Frontend Integration Strategies
  39. 39.Communication Between Micro-Frontends
  40. 40.Micro-Frontends: Pros and Cons for Large Teams
  41. 41.Real-Time: Polling, SSE and WebSockets
  42. 42.Real-Time Use Cases: Chat, Alerts, Live Data
  43. 43.Designing a Real-Time Data Flow
  44. 44.Scaling WebSocket Connections
  45. 45.Responsive Images: srcset, sizes and picture
  46. 46.Modern Image Formats: WebP, AVIF, JPEG XL
  47. 47.Lazy Loading Images and Videos
  48. 48.Video Streaming: HLS, DASH, Adaptive Bitrate
  49. 49.REST and GraphQL for Frontend Engineers
  50. 50.Batching, Throttling and Debouncing API Calls
  51. 51.Handling API Errors in the Frontend
  52. 52.Authentication Flows: OAuth and JWT
  53. 53.Global Error Boundaries in React
  54. 54.Error Reporting: Sentry and LogRocket
  55. 55.Graceful Degradation and Fallback UIs
  56. 56.Real User Monitoring (RUM)
  57. 57.CORS: Cross-Origin Resource Sharing
  58. 58.Preventing XSS (Cross-Site Scripting)
  59. 59.CSRF Protection for Frontend Apps
  60. 60.Content Security Policy (CSP)
  61. 61.Storing Auth Tokens: Cookies vs localStorage
  62. 62.PWA Manifest and Installability
  63. 63.Service Workers: Lifecycle and Caching Strategies
  64. 64.Offline Support and Background Sync
  65. 65.Push Notifications for Web Apps
  66. 66.Webpack vs Vite vs Parcel
  67. 67.Code Splitting, Tree Shaking, Asset Optimization
  68. 68.Module Resolution and Hot Module Replacement
  69. 69.Monorepo Tooling: Nx and Lerna
  70. 70.Atomic Design for Component Libraries
  71. 71.Theming and Customization in Design Systems
  72. 72.Accessibility in Component Libraries
  73. 73.Component Library Docs, Testing and Versioning
  74. 74.Publishing and Consuming a Component Library
  75. 75.Full-Text Search: Levenshtein and Fuzzy Matching
  76. 76.Indexing Large Datasets in the Browser
  77. 77.Search Performance: Debouncing and Web Workers
  78. 78.Integrating Backend Search Services
  79. 79.Choosing a Chart Library: D3, Chart.js, Recharts
  80. 80.Rendering Large Datasets: Canvas vs SVG
  81. 81.Interactive, Responsive Data Visualizations
  82. 82.Data Fetching and Aggregation for Dashboards
  83. 83.A/B Test Design and Rollout Strategies
  84. 84.Client-Side vs Server-Side A/B Testing
  85. 85.Feature Flags and Remote Configuration
  86. 86.Experiment Data Collection and Analytics
Frontend System Design Roadmap
20

Frontend System Design · Lesson 20 of 86 · 4 min

Props, State and Component Lifecycle

This is how you explain data flow inside a component and justify your design choices.

In an interview, you need to articulate how a component gets its data, how it manages its own data, and how it reacts to changes. This isn't just about React syntax; it's about demonstrating you understand the core principles of unidirectional data flow and state management at a component level.

Differentiating Props and State

The first question you'll get is often a variation of "What's the difference between props and state?" Your answer needs to be immediate and precise.

Props (properties) are how a parent component passes data to a child. They are read-only. A component cannot and should not change the props it receives. Think of them as function arguments. This enforces one-way data flow, which makes the application's behavior predictable.

State is data that a component owns and manages internally. It's private and can be changed by the component itself, usually in response to user interaction or network responses. When state changes, the component re-renders.

Interview Question: "A user clicks a 'like' button. Does the button's 'liked' status belong in props or state?"

Answer: "It belongs in state. The 'liked' status is internal data that the button component itself manages. A user interaction (a click) directly changes it. The parent component doesn't need to know about it unless other parts of the UI must react to the 'like' action, in which case the state might be lifted up."

How Changes Trigger Re-renders

A component re-renders when its props or state change. This is the fundamental mechanism for updating the UI in a component-based framework.

When you call a state setter function (like setCount(1)), you aren't changing the value directly. You are telling the framework to schedule a re-render of the component with the new state value. On the next render, the component function will execute again, and the useState hook will return the new value.

The trap: Directly mutating state (e.g., user.name = 'new name') will not trigger a re-render. The framework's renderer compares object references or primitive values to detect changes. Direct mutation keeps the reference the same, so the change goes undetected. Always use the setter function.

Managing Side Effects with useEffect

Side effects are any operations that affect something outside the component's render scope: fetching data, setting up a subscription, or manually changing the DOM. The useEffect hook is the designated place for this work.

The key to using it correctly is the dependency array.

  • useEffect(() => { ... }, []): The empty array means the effect runs once after the initial render (mount) and the cleanup function runs once before the component is destroyed (unmount). Use this for initial data loads or subscriptions.
  • useEffect(() => { ... }, [someValue]): The effect runs after the initial render and again anytime someValue changes. Use this to react to changes in props or state.
  • useEffect(() => { ... }): No array means the effect runs after every single render. This is almost always a bug and can easily cause infinite loops.

The trap: Forgetting the cleanup function for subscriptions, timers (setInterval), or event listeners will cause memory leaks. The function you return from useEffect is the cleanup. It runs before the component unmounts or before the effect runs again.

import React, { useState, useEffect } from 'react';

interface Post {
  id: number;
  title: string;
  body: string;
}

function DataFetcher({ postId }: { postId: number }) {
  const [post, setPost] = useState<Post | null>(null);
  const [loading, setLoading] = useState(true);
  const [error, setError] = useState<string | null>(null);

  useEffect(() => {
    // AbortController is the modern way to handle request cancellation.
    const controller = new AbortController();
    const signal = controller.signal;

    const fetchPost = async () => {
      setLoading(true);
      try {
        const response = await fetch(
          `https://jsonplaceholder.typicode.com/posts/${postId}`,
          { signal }
        );
        if (!response.ok) {
          throw new Error(`HTTP error! status: ${response.status}`);
        }
        const data: Post = await response.json();
        setPost(data);
        setError(null);
      } catch (e: any) {
        if (e.name !== 'AbortError') {
          setError(e.message);
        }
      } finally {
        setLoading(false);
      }
    };

    fetchPost();

    // The cleanup function. This runs when postId changes or the component unmounts.
    return () => {
      controller.abort();
    };
  }, [postId]); // Re-run the effect whenever postId changes.

  if (loading) return <p>Loading post...</p>;
  if (error) return <p>Error: {error}</p>;

  return (
    <div>
      <h3>{post?.title}</h3>
      <p>{post?.body}</p>
    </div>
  );
}

The Component Lifecycle in Practice

The terms "lifecycle" come from class components (componentDidMount, componentWillUnmount), but the concepts are the same with hooks. You need to be able to describe the sequence of events.

  1. Mount: The component is created and inserted into the DOM for the first time. useEffect with an empty dependency array [] runs here.
  2. Update: The component re-renders because its props or state changed. Effects with dependencies will run if those dependencies changed.
  3. Unmount: The component is removed from the DOM. The cleanup function from all useEffect hooks runs here to prevent memory leaks.

This diagram shows the flow.

Being able to walk through this flow for a given component—explaining when an API call happens, when a timer is set, and when it's cleared—is a strong signal in a system design interview.

Try it

Find a class component in one of your projects that uses componentDidMount to set up a subscription (like a setInterval or a WebSocket listener) and componentWillUnmount to tear it down. Rewrite it as a functional component using a single useEffect hook.

Next: We'll look at how to handle data at a larger scale in "Module Bundling Basics".

Lock it in — apply this lesson under interview conditions.

Try a free mock interviewPractice system design problems
Previous

Component-Based Architecture Principles

Next

Module Bundling Basics