Online React Compiler
Write a React component, press Run, and see it live. No npm install, no setup.
About this React compiler
This free online React compiler turns your JSX into JavaScript and shows the result in a live preview. It uses React 19.2. Write your component in App.jsx, add styles in styles.css, and press Run. Messages from console.log() and React warnings appear below the preview.
Everything runs in your own browser, so nothing is sent to our server. It is made for learning React, practising hooks, and testing a small component before you add it to a project.
How to use it
- Write your component in the App.jsx tab and export it with export default function App().
- Add styles in the styles.css tab. Use className in JSX, not class.
- Press Run. Your App appears in the preview. Press Run again after each change.
React examples
Open any of these from the Examples tab in the side bar.
Counter with useState
import { useState } from "react";
export default function App() {
const [count, setCount] = useState(0);
return (
<div className="card">
<h1>Hello, React!</h1>
<p>You clicked {count} times.</p>
<button onClick={() => setCount(count + 1)}>Click me</button>
</div>
);
}
List with keys
const students = [
{ id: 1, name: "Asha", marks: 82 },
{ id: 2, name: "Ravi", marks: 67 },
{ id: 3, name: "Meera", marks: 91 },
];
export default function App() {
return (
<ul>
{students.map((s) => (
<li key={s.id}>
{s.name}: {s.marks} {s.marks >= 80 && <strong>(top)</strong>}
</li>
))}
</ul>
);
}
Props and a form input
import { useState } from "react";
function Greeting({ name }) {
return <p>Hello, {name || "stranger"}!</p>;
}
export default function App() {
const [name, setName] = useState("");
return (
<div className="card">
<label>
Your name:{" "}
<input value={name} onChange={(e) => setName(e.target.value)} />
</label>
<Greeting name={name} />
</div>
);
}
Timer with useEffect
import { useEffect, useState } from "react";
export default function App() {
const [seconds, setSeconds] = useState(0);
useEffect(() => {
const id = setInterval(() => setSeconds((s) => s + 1), 1000);
return () => clearInterval(id);
}, []);
return <h1>{seconds} seconds</h1>;
}
What is React?
React is a JavaScript library for building user interfaces. You split the page into small components. Each component is a function that returns JSX, which looks like HTML inside JavaScript. When the data (the "state") changes, React updates only the parts of the page that changed.
JSX is not plain JavaScript, so a browser cannot run it directly. A tool must first change each JSX tag into a React.createElement() call. This page does that step for you in the browser, which is why you do not need npm, Vite or Create React App to try React here.
Common errors and how to fix them
Nothing to show yet. Add "export default function App()"The preview shows the component you export as default. Add export default before your main component.Each child in a list should have a unique "key" propWhen you render a list with map(), give each item a key that does not change, for example key={item.id}.Cannot import "axios"Only react and react-dom can be imported here. Other npm packages are not available. Write that part yourself in plain JavaScript.Adjacent JSX elements must be wrapped in an enclosing tagA component must return one parent element. Wrap the elements in a <div> or in a fragment: <>…</>.
Frequently asked questions
Which React version is used?
React 19.2.8, the development build. It shows full warning messages, which helps when you learn.
Can I use hooks such as useState and useEffect?
Yes. All React hooks work. Import them from "react", for example: import { useState, useEffect } from "react".
Can I install npm packages?
No. Only react, react-dom and react-dom/client can be imported. There is no npm install in this playground.
Can I write TypeScript (TSX)?
No. This page supports JavaScript with JSX. For TypeScript without JSX, use the TypeScript compiler page.
Where does my code run?
In a sandboxed frame inside your browser. It cannot read your cookies or the rest of this site, and it is not sent to our server.
Is my code saved?
Your last code is kept in this browser, so it is still there when you come back.
Can I build React Native apps here?
No. React Native needs a phone or an emulator. This page runs React for the web, which uses the same components, props, state and hooks.
Other free compilers
Learn to code with DevHives
Step-by-step lessons, DSA problems with a judge and mock interviews — made for students in India.
Create a free account