React JSX Playground
Static JSX tag check and hooks list — no runtime, runs locally.
Input
8 lines · 169 charsResult
1 line · 14 charsReact JSX Playground is a lightweight static checker for single-file React components — it does not render or execute your code. Supported checks: JSX tag balance (including self-closing tags and arrow functions inside attribute expressions), import rejection in single-file mode, a hooks table listing each useState and useReducer call with its initial value and owning component, and a warning for conditional hook calls. There is no live preview, no live hook values and no console capture. All analysis runs locally in your browser.
Examples
const [n, setN] = React.useState(0)hooks: [0]Hook values are recorded by call order and shown in the inspector.
throw new Error("boom")Error: boom — component stack shownThe error boundary keeps the rest of the page usable and shows a readable card.
import x from "pkg"Import statements are not supported in single-file modeThe pre-compile check explains that React is already available and no package imports are allowed.
About this tool
The React JSX Playground exists for the moment between "I have an idea for a component" and "I have set up a project". Type JSX, get a live preview, and inspect the state your hooks are holding without opening DevTools.
Compilation uses Babel with the classic React runtime so the generated code needs no JSX import wiring. Execution happens in an iframe sandboxed without same-origin access, with an origin-checked message bridge carrying console output, hook values and errors back to the page.
Single-file mode is deliberate: npm imports are rejected with a friendly message and React is preloaded. That constraint keeps the sandbox small and makes shared snippets self-contained.
What this tool does not do
- Only a single file is supported; there is no bundler, package resolver or multi-file import graph.
- Custom Babel plugins and TypeScript syntax beyond the JSX preset are not enabled.
- A debug build of React is used, so timing and warnings differ from a production bundle.
How to use this tool
Write a component
Type JSX into the editor or load the starter counter. The default export (or the last top-level component) is mounted into the preview.
Run and interact
Compilation runs on a short debounce. Click buttons and type into inputs in the preview to drive state changes.
Inspect hooks
The hooks table shows current useState and useReducer values in hook order, with the owning component name.
Toggle StrictMode
Turn StrictMode on to see development-time double invocation of effects and catch missing cleanup.
Use cases
Prototype an idea
Sketch a component and verify its interaction logic without scaffolding a build tool.
Prepare a reproduction
Build a minimal component that demonstrates a bug and share the packed source link in an issue.
Learn hooks
See useState and useReducer values change live and observe StrictMode effect behavior.
Sandbox messages
| Message | Direction |
|---|---|
| compile | page → iframe |
| hooks | iframe → page |
| console | iframe → page |
| error | iframe → page |
Messages are origin-checked in both directions; user code cannot reach the host document.
Common mistakes
Mistake:Trying to import npm packages.
Fix:Single-file mode has no module resolver: React is preloaded and import statements are rejected before compilation. Keep the example self-contained.
Mistake:Confusing StrictMode double effects with a bug.
Fix:Double invocation is intentional in development to expose missing cleanup. Toggle it off when you want to observe production-like behavior.
Mistake:Expecting the preview to touch host storage.
Fix:User code runs in a sandboxed iframe without same-origin access, so document and storage in the host page are unreachable by design.
Frequently asked questions
Are hooks like useState and useEffect supported?
Yes. useState, useReducer, useEffect, useMemo, useRef and the other standard hooks work because the preview runs real React. The inspector records useState and useReducer values by hook order so you can see them change as you interact.
Which React version runs?
A pinned React 18 UMD build is vendored with the tool and its version is shown in the toolbar badge. Pinning keeps shared snippets reproducible instead of depending on a moving CDN version.
Can I import npm packages?
No. This is a single-file scratchpad: import statements are rejected before compilation with a message explaining that React is already preloaded. For multi-package work you need a real project or bundler.
How is my code executed — is anything uploaded?
Compilation and execution happen locally. The compiled code runs in an iframe sandboxed without same-origin access, messages are origin-checked both ways, and no source is sent to a server. A share link packs the source into the URL fragment only when you choose to create it.
Why do effects run twice?
With StrictMode enabled, React intentionally double-invokes effects in development to reveal missing cleanup. Turn StrictMode off to see single invocation. This behavior is a debugging aid, not what happens in a production build.
References & standards
Related tools
AssemblyScript Playground
Write AssemblyScript-style functions, inspect a module preview, and run exports with a step-bounded offline evaluator.
Bash Playground
Test bash script snippets in a local mini-shell with seeded files, stdin, stream tags and visible sandbox limits.
C & C++ Playground
Check C and small C++ source for structural problems, map findings to lines and see the compile command for a local toolchain.
C# Playground & Snippet Checker
Static pre-flight checks for C# snippets — diagnostics, detected features and metrics, entirely in-browser.
Dart Playground
Write Dart, press Run, and see print output in your browser.
DBML Playground
Write DBML and see an ER diagram plus SQL DDL for Postgres, MySQL, SQLite and MSSQL, all in your browser.