React Playground
Write React components and see them live in a sandboxed preview, with a console, extra files and a zip download.
console.log messages and errors from your component appear here.
Shortcuts: Ctrl+Enter run · / search (use ⌘ on Mac)
Free Online React Playground
Try React components live. Write a component in App.jsx, and the preview shows it as you type, with a console for your messages and errors. Add more files for other components, download the project as one zip, and nothing you write is uploaded. Use it to test a component, try a hook or share a small React example without creating a project or installing anything.
How to use the React playground
- Edit App.jsx. It must export your root component, as in the sample:
export default function App() { ... }. - Watch the preview update. Messages from
console.logand any error appear in the console under it. - Press + to add a component file such as
Button.jsx, thenimport Button from './Button'in App.jsx. - Put styles in
styles.css(or another .css file). All CSS files are applied to the preview. - Open the ⋯ menu and choose Download all files (.zip) to take the project with you.
What is and is not included
You get React 18 with hooks, fragments and Strict Mode, and JSX works without any setup. You can add packages from npm with Add packages (they are downloaded from esm.sh only when you press Add). Folders work too: import Button from './components/Button'. For the underlying HTML, try the HTML to JSX converter, and for plain pages without a framework use the HTML/CSS/JS Playground.
Worked example
The sample is a counter and a small list. The core of App.jsx:
import { useState, useEffect } from 'react';
import './styles.css';
export default function App() {
const [count, setCount] = useState(0);
const [items, setItems] = useState(['Learn React', 'Build something small']);
useEffect(() => {
document.title = 'Clicked ' + count + ' times';
}, [count]);
return (
<main className="app">
<h1>Hello, React</h1>
<button type="button" onClick={() => setCount(count + 1)}>
Clicked {count} times
</button>
<ul>
{items.map((item) => (
<li key={item}>{item}</li>
))}
</ul>Result: a card with a heading, a button reading Clicked 0 times that counts up, a two-item list and an Add an item button.
Common mistakes
- Forgetting to export the component: without
export defaultthe preview says what to add. - Importing a package before adding it: press Add packages first, or the preview says what is missing.
- Writing
classinstead ofclassNameon an element. - Expecting type errors in a .tsx file: types are removed, not checked.