Skip to main content

React Playground

Write React components and see them live in a sandboxed preview, with a console, extra files and a zip download.

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>
<button type="button" onClick={() => setItems([...items, 'Item ' + (items.length + 1)])}>
Add an item
</button>
</main>
);
}

PreviewReady in 52 ms
Console

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

  1. Edit App.jsx. It must export your root component, as in the sample: export default function App() { ... }.
  2. Watch the preview update. Messages from console.log and any error appear in the console under it.
  3. Press + to add a component file such as Button.jsx, then import Button from './Button' in App.jsx.
  4. Put styles in styles.css (or another .css file). All CSS files are applied to the preview.
  5. 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 default the preview says what to add.
  • Importing a package before adding it: press Add packages first, or the preview says what is missing.
  • Writing class instead of className on an element.
  • Expecting type errors in a .tsx file: types are removed, not checked.

Frequently asked questions

Which version of React is this?
React 18, the production build. Components, hooks such as useState and useEffect, fragments and context all work. The version is fixed so a project behaves the same every time.
How do I use TypeScript?
Rename a file so it ends in .tsx (for example App.tsx). The types are removed before the code runs. They are not checked, so a type mistake will not show an error here; use the TypeScript Playground when you want type checking.
Can I import a package such as axios or lodash?
Yes. Press Add packages, type a name such as lodash or zustand@4, and press Add. The package is downloaded from esm.sh at that moment (your code is not sent, only the package name), pinned to the exact version, listed with its size, and saved with your project and its zip as package.json. Nothing is downloaded before you press Add. Packages that use React share the React of this page.
What do I need to export?
The root component must be the default export of App.jsx, like export default function App() { ... }. A named export called App also works.
Why does my effect run twice?
Strict Mode is on by default, as in a new React project, and it runs effects twice in development to help you find mistakes. Turn Strict Mode off under the editor to see the single run.
Is my code uploaded?
No. The code is compiled in your browser and runs in a sandboxed preview that has no network access unless you switch the internet option on.
Can this replace a full React project?
No. It is for small experiments: React 18 and your own files, with no packages, no router and no build tools. When an idea works, copy the files into your real project.

Related tools

More Playground

View all Playground tools →