About the React Formatter
What is a React formatter?
React components mix two languages in one file, JavaScript logic and JSX markup. That mix is exactly what breaks naive formatters, because a < can be a comparison or the start of a tag. This tool reads the whole component with a real parser, so both halves are formatted together: hooks, props destructuring, arrow handlers, and imports on the JavaScript side, and properly indented tags, attributes, and embedded expressions on the JSX side.
It runs on the Prettier engine with Prettier's TypeScript-aware parser, bundled locally with the page, no CDN fetch, no upload, works offline. That parser covers plain .jsx and .tsx equally, so typed props, generic components, and decorators format correctly instead of being spaced out like comparison operators. The trade-off is that the file has to parse before it can be reprinted, so a half-written component is reported as a syntax error rather than being formatted on a best-effort basis.
How to Use This Tool
- Add your component. Paste JSX/TSX into the left editor, open a file, or click Sample.
- Watch it format. The JavaScript structure and the JSX markup are both indented live as you type.
- Tune the style. Choose your indentation, single or double quotes, and whether semicolons are added.
- Take the result. Copy it or download it as a
.jsxfile.
Example
A component written on one line will be converted to a readable arrow function with its props broken out:
const Card=({title,items})=>{return(<div className="card"><h2>{title}</h2><ul>{items.map(i=><li key={i}>{i}</li>)}</ul></div>)}
const Card = ({ title, items }) => {
return (
<div className="card">
<h2>{title}</h2>
<ul>
{items.map((i) => (
<li key={i}>{i}</li>
))}
</ul>
</div>
);
};
Every nested element is indented to its depth and the map callback is broken onto its own lines, so the shape of the rendered markup is visible at a glance. Line breaks are only added where JSX ignores them, so what renders does not change.
Common Use Cases
- Cleaning up component logic: Untangle the hooks, handlers, and helpers around your render output.
- Reading pasted components: Make single-line snippets from chat or docs reviewable.
- Normalizing style: Convert a component's indentation and quote style in one pass.
- Safe by default: Format files where you absolutely cannot afford a broken tag.
Plain JavaScript? Use the JavaScript Formatter. Typed code? The TypeScript Formatter. Standalone markup? The HTML Formatter.
Frequently Asked Questions
Will it break my JSX?
No. The whole component is parsed into a syntax tree before anything is printed, so tags, attributes, spreads, and embedded expressions are re-indented as structure rather than rewritten as text. If the file cannot be parsed, nothing is emitted at all, so there is no state in which you get half-rebuilt markup.
Is the JSX markup itself re-indented?
Yes. Nested elements are indented to their depth, long attribute lists are broken onto their own lines, and self-closing tags are normalized. Reformatting JSX safely needs a full Babel-grade parser, which is what this tool runs, so the markup is restructured from the syntax tree rather than guessed at from tokens.
Does it work with hooks and modern React?
Yes. useState/useEffect and custom hooks, destructured props with defaults, arrow-function handlers, fragments, and ES module imports/exports all format correctly.
Can I format TSX?
Yes, paste it in. The parser is TypeScript-aware, so typed props, interfaces, generic components, and decorators format the same way they do in the TypeScript Formatter, alongside the JSX.
What happens if my component has a syntax error?
The status badge turns red and names the problem, and the output pane stays empty rather than showing a half-formatted guess. Because the formatter builds a full syntax tree, it needs the component to parse before it can reprint it. Fix the reported line and formatting resumes as you type.
Is my code uploaded anywhere?
No. The formatting library ships with the page and runs locally (no CDN, no uploads, no logging) and the tool works offline once loaded.