Refactor duplicate code

Refactor duplicate code in JavaScript — with the four heights of help laid out: do it now, make it easier for the next person to accept, work out the right move when you are stuck, and learn the pattern so it stops coming back.

4prompt heights
Open it in the interactive atlas →

The four heights

The same task, four distances: today's deadline, the next reviewer, the stuck moment, the pattern.

Execute — do the immediate task

+
Two components, UserCard.jsx and MemberCard.jsx, duplicate rendering of avatar, name and role.…
Two components, UserCard.jsx and MemberCard.jsx, duplicate rendering of avatar, name and role. Refactor to extract a shared AvatarNameRole component in components/common/AvatarNameRole.jsx, update both callers to use it, keep prop names the same for backwards compatibility, and run unit tests before committing 'refactor: extract AvatarNameRole'.

Improve — make it easier to accept

+
Before extracting the shared component, make reviewing simpler: show the duplicate JSX blocks and…
Before extracting the shared component, make reviewing simpler: show the duplicate JSX blocks and the minimal shared props, propose a single prop API that preserves current behavior, list edge cases like missing role or avatars, and highlight any CSS class differences that need consolidating so the reviewer can accept the refactor quickly.

Decide — diagnose the stuck moment

+
I discovered nearly identical avatar-and-name JSX in UserCard and MemberCard. I want to extract a…

I found near-identical JSX in two places.

I discovered nearly identical avatar-and-name JSX in UserCard and MemberCard. I want to extract a shared component but worry about subtle styling differences and prop expectations that could break downstream pages. I can’t tell which differences are intentional. Which tests and quick manual checks should I run to safely extract the component and preserve current behavior across the site?

Become — change the pattern

+
Over time we end up with many near-duplicate components because each engineer extracts a version…

We keep extracting the same component slightly differently each time.

Over time we end up with many near-duplicate components because each engineer extracts a version just for their page, causing combinatorial maintenance cost. Where do we consistently lose time and credibility—naming, prop shape, CSS scope, or lack of a shared component library—and what single habit would reduce duplicate drift most effectively?

Next to this one

Other programming language work people do in JavaScript.

Every task here came from the work, not from a feature list — which is why the prompts name what you want done and never the button that does it. The tool changes; the work does not.
Copyright © LLOS.ai · 2026 — original pedagogy, voice, and design — all rights reserved.

The rest of the map

Same library, five ways in.