惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Hugging Face - Blog
Hugging Face - Blog
WordPress大学
WordPress大学
Microsoft Azure Blog
Microsoft Azure Blog
F
Fortinet All Blogs
B
Blog RSS Feed
Last Week in AI
Last Week in AI
The Cloudflare Blog
大猫的无限游戏
大猫的无限游戏
人人都是产品经理
人人都是产品经理
P
Proofpoint News Feed
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Microsoft Security Blog
Microsoft Security Blog
博客园 - 三生石上(FineUI控件)
Y
Y Combinator Blog
GbyAI
GbyAI
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
小众软件
小众软件
雷峰网
雷峰网
C
Check Point Blog
阮一峰的网络日志
阮一峰的网络日志
博客园 - 叶小钗
博客园 - 司徒正美
U
Unit 42
量子位

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
I Built a Screenshot-to-React Generator in 3 Hours
Norbert Mado · 2026-05-27 · via DEV Community

I got tired of translating Figma screens and UI screenshots into JSX before I could touch any real frontend work — routing, state, architecture, the stuff that actually matters. So I built a tool to do it for me.
Drop a screenshot. Get a live, rendered React + Tailwind component. Streaming. In your browser. No build step.
Here's how it works and what broke along the way.

The Stack

  • Next.js 14 — frontend, split-panel UI
  • Go — backend, image compression, SSE streaming
  • Claude API (claude-sonnet-4-5) — vision + code generation
  • Babel Standalone + Tailwind CDN — zero-build iframe preview
  • localStorage — conversion history

How It Works
Screenshot → Go (compress + resize) → Claude Vision (streaming) → SSE → Next.js → iframe preview

The Go backend compresses the image to under 5MB, base64 encodes it, and opens a streaming connection to Claude's API. Each text delta gets forwarded to the browser as a JSON SSE event:

data: {"delta":"import"}
data: {"delta":" React from 'react';"}

Enter fullscreen mode Exit fullscreen mode

The frontend accumulates the stream into a code string. Once generation finishes, the code gets injected into an iframe using document.write() — React, Babel, and Tailwind loaded via CDN. The component renders instantly with no build step.

The Bugs That Hurt
Chunk concatenation. Claude streams tokens. import and React arrive as separate events. Early on I was joining them naively and getting importReact from 'react' — which Babel rejects. Fix: wrapped each delta in a JSON object on the Go side, read obj.delta on the frontend. JSON preserves whitespace exactly.

Import statements in the iframe. The iframe loads React via CDN. If the generated code also has import React from 'react', Babel throws. Fix: stripped all imports and replaced export default before injecting:

const clean = code
  .replace(/^import\s+[\s\S]*?from\s+['"][^'"]*['"];?\s*$/gm, "")
  .replace(/^export\s+default\s+/m, "const __Component__ = ")
  .trim();

Enter fullscreen mode Exit fullscreen mode

Image media type mismatch. Screenshots saved as .png sometimes contain JPEG bytes. Claude rejects the mismatch. Fix: since the Go compressor always outputs JPEG, I hardcoded image/jpeg as the declared media type regardless of the input format.

The Prompt That Works
You are an expert React and Tailwind CSS developer.
Generate a complete, production-ready React functional component
that faithfully reproduces the screenshot's layout, spacing,
colors, and typography.

  • Tailwind utility classes only — no inline styles
  • Realistic placeholder text, not Lorem Ipsum
  • Mobile-first responsive classes
  • Hover and focus states on interactive elements
  • Return ONLY the component code, no markdown fences
  • Self-contained, no required props "No markdown fences" is critical — without it Claude wraps output in triple backticks and Babel chokes on them.

What It Actually Produces
Tested on a Personal Details mobile screen, a dark SaaS landing page, and an analytic dashboard. All three came back with correct layout structure, color palette, component hierarchy, and interactive states. Light tweaking needed, but production-usable as a starting point.
What it doesn't nail: exact hex colors (approximates to nearest Tailwind value), complex animations, data-driven elements.

Cost
Under $5 total — including every debug run and demo conversion during the build.
Each conversion is ~500–800 prompt tokens + image tokens + ~2000 generation tokens. A few cents per screenshot. The tool replaces 30–60 minutes of manual JSX work per screen.

The Point
This doesn't replace frontend engineering. It removes the part that doesn't need one — translating static visuals into boilerplate markup. Get the structure from the screenshot, then spend your time on architecture, state, performance, and the interactions that actually require expertise.
Three hours to build. $5 to run. Every hour saved after that compounds.

Code
Full source on GitHub: github.com/norbertose/screenshot-figma-to-react
Stack: Next.js · Go · Claude API. Clone it, swap in your ANTHROPIC_API_KEY, and run.
The $5 subscription is still active.