b2KIT

React Component Playground

Build and preview React components with JSX, hooks, and state in an isolated sandbox environment.

Tested tool guide Tested browser tools Checked August 16, 2026

What React Component Playground does, with a checked example

Paste a component into the editor pane and a live preview of it renders beside the code, updating as you type. Hooks such as useState and useEffect behave normally, so stateful UI can be prototyped with no build step and no local project. The common surprise: it is not a mini version of your app. Only the packages the sandbox provides can be imported, your project's global CSS is absent, and the component remounts on every edit, so state resets mid-work. The preview also shows only what your code renders, so a component that is defined but never rendered leaves the pane blank.

Worked example

A concrete input and expected output from the current implementation.

Input

function Counter() {
  const [count, setCount] = React.useState(0);
  return (
    <button onClick={() => setCount(count + 1)}>
      Clicks: {count}
    </button>
  );
}

Expected output

The preview pane renders a button labeled 'Clicks: 0'. Each click increments the number, so after two clicks the button reads 'Clicks: 2'.

useState(0) starts count at 0 and setCount(count + 1) adds 1 per click, so the label always equals the number of clicks. This is the basic stateful pattern the playground is built to demonstrate.

How the result is produced

1

Live re-render on every edit

The editor re-evaluates your code whenever you pause typing, and the preview reflects the new render almost immediately. Each re-evaluation remounts the component, so hooks re-run from their initial values: useState resets, useEffect fires again, and interaction state such as text in an input is lost. Syntax errors, undefined variables, and runtime throws are shown in an error panel rather than crashing the page.

2

Isolated execution scope

Component code runs apart from the host page, so it cannot reach the surrounding site's scripts or storage, and nothing is sent over the network. Only the packages the sandbox exposes are importable; any other import fails with a module-not-found error. Project-wide styles do not carry over, so the preview looks unstyled until you add CSS, and components that fetch remote data show a failed request instead of real content.

Good uses

  • Prototype a stateful component - a counter, toggle, or form with validation - and iterate on the JSX until the behavior is right, without creating a project or starting a dev server.
  • Reproduce a rendering bug: paste the failing component into the clean sandbox, read the error panel, and decide whether the fault is in the component itself or in the app around it.
  • Demonstrate a React pattern - hooks, props, conditional rendering - as a runnable snippet that a colleague or student can edit and watch re-render live.

Limits and checks

  • Import limits. Only packages the sandbox provides are importable. Code that imports your own modules, Node built-ins, or npm packages outside the allowlist fails with a module-not-found error, so a component that works in your app can error here.
  • State resets on every edit. Any keystroke remounts the component, so mid-interaction state - a partially filled form, an open menu - vanishes. That is the sandbox re-running your code, not a defect in it.
  • A blank preview does not mean broken code. If the snippet only defines a component and never renders it, the pane stays empty, and without project CSS the output looks unstyled even when the markup is correct.

Common questions

Can I import any npm package?

Only the packages the sandbox preloads. Typical playgrounds expose React and a small set of helpers; anything else fails with a module-not-found error in the panel. If your component needs an unlisted library, inline the logic you need or reduce the snippet to a minimal reproduction that only uses React.

Why does my component lose state every time I edit the code?

Each edit makes the sandbox re-evaluate and remount the component, so hooks re-run from their initial values. That is expected here and does not predict your real app, where re-renders keep state. If state resets even without edits, after a refresh, check that useState is called at the top level of the component, not inside a condition or callback.

References and verification

The example and behavioral notes were checked against the browser implementation. Standards and primary references below define the relevant format, formula, or platform behavior.

Related Tools