Track 04 · Lesson 11 of 15Code that stays easy to change

Track 04 · Code that stays easy to change

YAGNI: You aren't gonna need it

Lesson 11 of 15· 5 min

You aren't gonna need it: don't build for requirements you only imagine.

Count the states

Uncheck the props nobody uses

69,120

Possible states of one Button that should look and behave right

Check and uncheck props to see the effect.

11 of the checked props have no caller anywhere in the app, yet they multiply the states you have to keep working.

Button.tsxWithout it
type ButtonProps = {
  variant?: "primary" | "secondary" | "ghost" | "danger" | "link";
  size?: "sm" | "md" | "lg";
  disabled?: boolean;
  loading?: boolean;
  iconLeft?: ReactNode;
  iconRight?: ReactNode;
  fullWidth?: boolean;
  asChild?: boolean;
  tooltip?: string;
  confirm?: string; // asks "Are you sure?" before onClick
  rounded?: "none" | "md" | "full";
  theme?: "light" | "dark" | "auto";
  analyticsId?: string;
  onClick?: () => void;
  children: ReactNode;
};

// Used in the app today: variant="primary", variant="ghost", disabled.
// Everything else is a guess about the future, and every guess needs upkeep.

Every option multiplies#

Each prop doesn't add work, it multiplies it. A Button with a 5-way variant and a disabled flag has 10 states to keep looking and behaving right. Add size, loading, icons, tooltip and the rest, and it's millions. Nobody tests millions of states, so the unused ones rot quietly, like the confirm prop's focus bug.

Speculation has a price#

Code built for an imagined future costs you three times: to build it, to keep it working through every refactor, and to read around it. And when the real requirement finally arrives, it rarely looks like the one you imagined. Build what today's callers need; adding a prop later, when someone asks, is easy.

Check yourself

Why do unused props on a shared component cost so much?