$ show balajmarius/svg2jsx
svg2jsx is a web application that converts SVG markup into valid JSX code for React components. It provides a real-time editor with a split pane: left for SVG input (with drag-and-drop support) and right for the generated JSX output. The conversion pipeline runs server-side via a Next.js API route, applying SVGO optimization, attribute normalization (camelCase, className, style objects), and optional formatting as a React component (with memo, TypeScript, and quote configuration). The frontend is built with React 18, Next.js 15, TanStack Query, Tailwind CSS, and react-ace for the editor. The codebase is well-structured, with clean separation of concerns between UI components, state management (React Context), and pure conversion logic. Tests cover the core conversion function. The app is designed for single-user, client-side usage with a simple API endpoint.
The LLM identified 3 files worth highlighting for reuse:
Recursively transforms an SVG node tree (from svg-parser) into JSX-compatible properties. Converts kebab-case attributes to camelCase, 'class' to 'className', and inline CSS strings to JavaScript style objects using style-to-js. Handles data-* attributes as exceptions. This is a pure, reusable function that encapsulates the core SVG-to-JSX attribute mapping logic. It can be extracted and reused in any project needing SVG-to-JSX conversion, independent of the hosting framework.
Serializes a transformed SVG node tree back into a JSX string. Contains two key functions: `cssObjectToString` converts a JavaScript style object into JSX inline style syntax (properly quoting string values and handling numeric values), and `stringify` recursively builds the JSX string with opening/closing tags. The `cssObjectToString` function is particularly reusable for any JSX code generation that needs to serialize style objects. The overall stringify logic is a clear, self-contained implementation of a recursive tree serializer.
A custom React hook that combines a boolean toggle state with localStorage persistence. It uses `useToggle` from usehooks-ts for the toggle behavior and `useLocalStorage` for persistence, synchronizing the two via a useEffect. This is a clean, reusable pattern for any application that needs to persist a boolean preference (e.g., settings toggles) across sessions. It is self-contained and only depends on stable external libraries.