Everyday Programmer
Field Notes

How I Would Rescue a 1,400-Line React Component

A staged approach to modernizing a huge legacy React component: stabilize first, then draw data and rendering boundaries, then migrate piece by piece.

2 min readfield notes, react, refactoring
Illustration for "How I Would Rescue a 1,400-Line React Component" — Everyday Programmer

Every codebase has one: the component that started as a table, grew a chart, then a form, then a real-time feed, and now weighs in at 1,400 lines with eleven useEffect hooks that nobody fully understands.

Here's the rescue plan I'd follow — and have followed. The order matters more than the steps.

Step 0: Measure before refactoring

Never start with "clean up the component." Start with evidence:

rescue-measurements.txt
text

The measurements tell you which boundary to draw first. A component that re-renders on every keystroke needs different surgery than one that's merely long.

Step 1: Stabilize user impact

If users are feeling pain, fix that before architecture:

  • Server-side pagination. The single highest-leverage change for any data-heavy table. Ten thousand rows should never cross the wire.
  • Row virtualization for what remains rendered client-side.
  • Debounced, server-side filtering. Filtering 10,000 rows on the client, on every keystroke, is the classic silent killer.

These are changes a reviewer can approve without a migration plan — and they buy the breathing room for structural work.

Step 2: Draw the boundaries

A 1,400-line component is usually six components fused together. The seams in mine were:

boundaries.txt
text

Extract in dependency order: pure helpers first (zero risk), then data transforms (testable), then leaf components (table, chart), and the orchestration shell last.

Step 3: Migrate incrementally

Each extraction is its own PR, shippable and revertable:

  1. Extract pure utility functions + unit tests
  2. Extract the data layer behind the same props the monolith used
  3. Extract leaf components one at a time (row, chart, controls)
  4. Replace orchestration last, once children are stable

At every step the app ships. No "big rewrite branch" that drifts for three months.

Before and after

before-after.txt
text

The component count went up. The line count stayed similar. What changed is that each concern now has one owner, one test surface, and one reason to re-render.

That's the actual goal of a rescue — not prettier code, but a system where change is cheap.

Keep reading

Related articles