AI summary by TwinMind

React's Billion Dollar Problem

Theo - t3․gg

6m 27s

Programming Lore and Billion Dollar Mistakes

  • Tony Hoare's null references invention called "billion dollar mistake"
    • Added because "really easy to add and felt bad not to"
    • Cost at least $1B in errors, outages, debugging pain
  • Ryan Dahl (Node.js/Deno creator) advice: avoid "cute" additions to languages/frameworks
    • Cute/simple features often cause most pain long-term

React useEffect as Potential Billion Dollar Problem

  • Thesis: useEffect has similar costly pitfall patterns
  • Common mistake: missing dependency array leads to excessive re-runs
  • Example: tracking/analytics code running on every render instead of once

Code Examples and Common Pitfalls

  • Basic useEffect without dependency array runs on every render
  • Missing empty array [] causes analytics to run twice minimum
  • When parent component state changes, child useEffect re-runs unexpectedly
  • ESLint dependency warnings can lead developers into infinite loops
    • Adding state variable to dependency array that gets updated inside useEffect
    • Creates cycle: useEffect runs → updates state → triggers useEffect again

Real-World Cost Examples

  • Ping video codebase incident:
    • Deep useEffect managing mic device selection
    • Rare Linux user cases triggered infinite loops
    • Sent thousands of websocket messages per second
    • Random $1000+ bills every few months
    • Difficult to debug (Linux users often had ad blockers, poor analytics)
  • Twitch incident mentioned:
    • useEffect triggering ad runs inappropriately
    • Should have used button click handlers instead

Solutions and Best Practices

  • Use functional state updates to avoid dependency issues
    • setCount(current => current + 1) instead of setCount(count + 1)
  • Careful consideration of dependency arrays
  • Understanding when effects should/shouldn't run
  • Proper code review practices for useEffect usage

Overall Assessment

  • useEffect foot guns are real and costly
  • Not yet at billion dollar cost level but approaching quickly
  • Still defends useEffect as overall good pattern despite pitfalls
  • Requires careful usage and understanding of behaviors
  • Not reason to avoid React, but reason for caution

TwinMind

Get summaries like this for your own meetings

TwinMind takes notes in the background during meetings, lectures, and calls, then writes the summary for you.

Free plan to get started

No bot joins your calls

Phone, desktop & Chrome apps

Your next meeting, summarized like this

TwinMind listens in the background and turns meetings, lectures, and calls into searchable notes you can chat with. Start free.

Available on phone, desktop & Chrome

Your next meeting, summarized like this

TwinMind listens in the background and turns meetings, lectures, and calls into searchable notes you can chat with. Start free.

Available on phone, desktop & Chrome

Your next meeting, summarized like this

TwinMind listens in the background and turns meetings, lectures, and calls into searchable notes you can chat with. Start free.

Available on phone, desktop & Chrome