Skip to content
    Explorer
    Project
    package.json
    App.js
    index.js
    styles.css
    components
    Button.jsx
    Card.jsx
    hooks
    useCounter.js
    Dependencies
    react^18.2.0
    react-dom^18.2.0
    App.js
    styles.css
    index.js
    src › App.js
    http://localhost:3000

    Building preview...

    Terminal
    ➜ webfiddle-react-app
    Type "help" for available commands.
    $
    main* 0 Ready
    Ln 1, Col 1UTF-8javascript

    React Online Compiler and Playground with Live Preview

    This React online compiler turns JSX and TSX into JavaScript in your browser and renders your components in a live preview. Write code across several files and the preview re-renders about a second after you stop typing. You can switch between React 16.14, 17.0, 18.2 or 18.3, loaded from React's official UMD builds, while Babel compiles your code inside a sandboxed iframe and the console below the preview shows logs and runtime errors. Use it as a React playground or online React editor with no npm install, bundler or server to set up.

    How to use the React online compiler

    1. Open the React playground. A starter project with App.js, two components and a custom hook loads and renders in the preview.
    2. Edit App.js or any other file in the explorer. Use the explorer to create files and folders, or pick a sample project from its samples menu.
    3. Watch the preview update about a second after you stop typing, or press Ctrl+S to run it immediately.
    4. Read console.log output and runtime errors in the terminal panel below the preview.
    5. Add a library by typing npm install followed by its name in the terminal, then use the global variable the library defines.
    6. Choose a React version from the selector in the status bar, and press Share to copy a link to the whole project.

    Features

    • React 16.14, 17.0, 18.2 or 18.3, selectable from the status bar (18.2 by default)
    • JSX in .js and .jsx files, and TypeScript syntax in .ts and .tsx files, compiled by Babel in the browser
    • Multi-file projects with folders, a file explorer, editor tabs, search and quick open (Ctrl+P)
    • Local imports between files, such as import Button from './components/Button'
    • Live preview in a sandboxed iframe that refreshes a second after you stop typing, or straight away with Ctrl+S
    • Terminal with npm install, npm uninstall and npm list, checked against the npm registry
    • 17 sample projects, including a to-do list, Kanban board, data grid, Markdown editor and TypeScript demo
    • Projects auto-save to local storage and can be exported or imported as ZIP files or shared as a URL

    What works and what doesn’t

    • React 19 is not available. The playground loads React from UMD builds, and React stopped publishing UMD builds with version 19.
    • npm packages are added as classic script tags from jsDelivr, not as ES modules. A package loads only if it publishes dist/<name>.min.js, and you use its global variable (for example axios, or _ for lodash) instead of an import statement.
    • Import paths are resolved from the project root rather than from the importing file, and only default and named imports and exports are handled. import * as and anonymous export default functions are not supported.
    • Babel removes TypeScript types but never checks them, so type mistakes do not produce errors.
    • Only a file named styles.css is applied as CSS; importing any other stylesheet has no effect.
    • The preview uses React development builds and compiles code in the browser, so it is slower than a production build and unsuitable for performance measurements.

    Example programs

    List with useState in the React playground

    Paste into App.js. Each click creates a new array instead of mutating the old one, which is what lets React detect the change and re-render.

    import { useState } from 'react';
    
    export default function App() {
      const [items, setItems] = useState(['Read the React docs']);
      const [text, setText] = useState('');
    
      const addItem = () => {
        if (!text.trim()) return;
        setItems([...items, text.trim()]);
        setText('');
      };
    
      return (
        <div>
          <input value={text} onChange={(e) => setText(e.target.value)} placeholder="New item" />
          <button onClick={addItem}>Add</button>
          <p>{items.length} item(s)</p>
          <ul>
            {items.map((item, i) => <li key={i}>{item}</li>)}
          </ul>
        </div>
      );
    }
    

    Stopwatch with useEffect cleanup

    The effect starts an interval only while running is true, and the cleanup function clears it when you pause or the component unmounts.

    import { useState, useEffect } from 'react';
    
    export default function App() {
      const [seconds, setSeconds] = useState(0);
      const [running, setRunning] = useState(false);
    
      useEffect(() => {
        if (!running) return;
        const id = setInterval(() => setSeconds((s) => s + 1), 1000);
        return () => clearInterval(id);
      }, [running]);
    
      return (
        <div>
          <h2>{seconds}s</h2>
          <button onClick={() => setRunning(!running)}>{running ? 'Pause' : 'Start'}</button>
          <button onClick={() => setSeconds(0)}>Reset</button>
        </div>
      );
    }
    

    Typed props in a TSX component

    Save as components/Badge.tsx, then render it from App.js after adding import Badge from './components/Badge'. Babel strips the BadgeProps type before the code runs.

    type BadgeProps = {
      label: string;
      tone?: 'info' | 'success';
    };
    
    export default function Badge({ label, tone = 'info' }: BadgeProps) {
      const color = tone === 'success' ? '#15803d' : '#1d4ed8';
      return <span style={{ color, fontWeight: 600 }}>{label}</span>;
    }
    

    Frequently asked questions

    What is a React online compiler?

    A React online compiler, also called a React playground, is a browser-based editor that turns JSX into JavaScript and renders your components immediately, without creating a project with npm or a bundler. WebFiddle's version supports multiple files, JSX and TSX, a live preview, a console, 17 sample projects and shareable links, and it runs on your device.

    Which React versions can I use?

    You can pick React 16.14, 17.0, 18.2 or 18.3 from the selector in the status bar; 18.2 is the default. The preview calls createRoot on React 18 and ReactDOM.render on older versions. React 19 is not offered because it no longer ships the UMD builds this playground loads.

    Do I need to run npm install to use this online React editor?

    No. React, ReactDOM and Babel load from public CDNs when the preview starts. For an extra library, type npm install and the package name in the terminal: the playground checks the npm registry, adds the package to package.json and loads its browser build from jsDelivr as a script.

    Why does importing an npm package fail in the preview?

    Packages are added as classic script tags, not ES modules, so an import statement naming a package has nothing to resolve. Use the global variable the library defines instead, such as axios, or _ for lodash. Only packages that publish a dist/<name>.min.js browser build load this way, and many ESM-only packages do not.

    Can I write JSX and TypeScript in this online React compiler?

    Yes. Files ending in .js or .jsx can contain JSX, and files ending in .ts or .tsx can also use TypeScript syntax. Babel removes type annotations before the code runs but does not type-check them, so type mistakes are not reported. For type checking, try code in the TypeScript playground.

    Where is my React project saved?

    Your files auto-save to local storage in your browser, so they are still there when you come back on the same device and browser. Nothing is uploaded to WebFiddle. To move a project elsewhere, export it as a ZIP file, or press Share to copy a URL that contains the whole project in compressed form.

    Embed this sandbox

    Paste this iframe into any web page and readers can run code without leaving it. The snippet travels in the URL, so there is nothing to host and no account to create. Open the sandbox, write your example, press Share, then append that link’s query string to the embed URL to preload it.

    <iframe src="https://webfiddle.xyz/embed/react" width="100%" height="480" loading="lazy"
            style="border:1px solid #ddd;border-radius:8px"
            title="WebFiddle react sandbox"></iframe>
    Preview the embed

    Related articles

    Related sandboxes

    Official documentation