From Design Mockup to React Page: The Real Challenge Is Slicing Assets
This article explains why converting a product mockup into a working React page is rarely blocked by component coding, and why the asset-slicing layer is the most underestimated part of the work. It breaks down four hidden costs of slicing—ambiguous sizing and spacing, inconsistent asset exports, multi-resolution and format choices, and missing state coverage—then presents a reusable engineering workflow: structure annotation before coding, a minimal set of design tokens, asset naming and directory conventions, using flex/grid layout instead of hard-coded pixel alignment, and a state matrix defined upfront. It closes with a Definition of Done checklist for structure, styling, assets, layout, states, and maintainability.
1. Reframing the Problem: Why Writing Components Is Not the Bottleneck
Turning a product mockup into a runnable React page usually involves a straightforward stack: React for componentization and state management, Next.js for routing and rendering modes, and Tailwind CSS for atomic styling. What actually consumes time is the translation layer between the mockup and the code—the slicing work that is routinely underestimated.
Slicing is not just “exporting images.” It covers at least four things: identifying the interface structure and hierarchy, measuring dimensions and spacing, exporting image and icon assets, and handling multiple resolutions and multiple states. Miss any one of them and the page ends up “looking close, but not right.”
2. Four Hidden Costs of Slicing
Ambiguity in dimensions and spacing
Annotations on a mockup usually cover only the primary elements. Details such as card padding, list row height, and vertical alignment between buttons and inputs are often omitted. Developers are left eyeballing values, which produces 1–2px offsets across different screens.Inconsistent asset exports
The same image may exist in several versions (with or without text, dark or light, different resolutions). If naming is messy and there is no unified directory, you get duplicate assets, wrong references, and bloat.Multi-resolution assets and format choices
On 1x/2x/3x screens, bitmaps need multiple resolution variants, while icons and simple shapes are better served by vector formats. Using bitmaps for everything looks blurry and inflates the bundle.Insufficient state coverage
Mockups typically show only the default state. A real page needs hover, focus, active, disabled, loading, empty, and error states; missing any of them creates an interaction gap.
3. An Engineering Approach: Turning Slicing into a Reusable Process
1) Annotate the structure first, then write code
Before starting, break the mockup into a tree of “region → component → element,” and mark which parts are layout containers, which are repeated lists, and which are overlays. For example:
Page├─ Header (fixed height)├─ Main│ ├─ FilterBar (wraps)│ └─ CardList (repeated items)│ └─ Card (cover image, title, tags)└─ Footer
Once the structure is clear, component boundaries emerge naturally, which avoids writing the whole page as one giant component.
2) Define a minimal set of usable design tokens
Extract colors, font sizes, radii, shadows, and spacing into tokens, and reference them consistently through Tailwind theme extension:
// tailwind.config.js (illustrative)theme: {extend: {colors: { brand: '#2563eb', surface: '#0f172a' },spacing: { card: '16px', gutter: '24px' },borderRadius: { card: '12px' }}}
The payoff of tokenization: later tweaks change one place instead of being replaced one by one across dozens of components.
3) Standardize assets: naming, directories, and formats
A workable convention: assets/{type}/{name}@{scale}.{ext}. Prefer vector for icons and simple shapes, use bitmaps for photo-like content with on-demand multi-resolution variants, and delete duplicate exports of the same asset from the mockup to avoid bloat.
4) Replace pixel alignment with layout capabilities
If flex or grid can solve it, do not hard-code width and height. Reserve fixed heights for regions that genuinely need them (such as the top bar). Example:
<div className="flex items-center gap-gutter"><img src="/assets/icon/search@2x.png" alt="" className="h-5 w-5" /><input className="flex-1 bg-transparent outline-none" placeholder="Search" /></div>
5) Build the state matrix first
List each component’s state matrix before coding and implement it item by item, avoiding the rework of “do the default state first, add interactions later”:
- Interaction states: hover / focus / active / disabled
- Data states: loading / empty / error / success
- Responsive states: wrapping on narrow screens, multiple columns on wide screens
4. Things to Watch When Collaborating Across AI Coding Tools
When using AI coding tools or cloud development environments, prepare the context thoroughly: the structure tree, the token table, the asset inventory, and the state matrix. Such tools are good at generating boilerplate code and style drafts, but alignment details still require manual verification. For cloud collaboration, you can rely on general-purpose capabilities (such as object storage for hosting static assets, logging services for recording build issues, and monitoring and alerting for tracking production anomalies), but do not depend on the “exclusive capabilities” of any single tool.
5. Definition of Done Checklist
- Structure: component boundaries map one-to-one to mockup regions, with no giant component
- Styling: all colors, spacing, and radii come from tokens, with no scattered magic values
- Assets: consistent naming, no duplicates, sensible formats, complete resolutions
- Layout: no overflow caused by hard-coded width or height; correct on both narrow and wide screens
- States: every item in the state matrix passes
- Maintainability: clear directory structure, and later changes affect only a local scope
6. Closing Thoughts
The real difficulty in reproducing a mockup is translating a “visual description” into “maintainable engineering constraints.” Once slicing is decomposed into five things—structure annotation, tokenization, asset conventions, layout strategy, and a state matrix—and paired with a clear Definition of Done checklist, page reproduction shifts from “going by feel” to a reproducible process, and rework drops significantly.
