R
React Playground Editor
Featured on NPM

Interactive Code Editor
for React

A powerful, feature-rich React component with live preview, file management, terminal, and dependency management. Perfect for online IDEs and coding tutorials.

1.0.7+
Latest Version
100%
TypeScript
0
Dependencies
React Playground Editor
Files
📁 src/
📄 App.jsx
📄 index.js
Editor
import React from 'react'

function App() {
  return (
    <div>
      Hello World!
    </div>
  )
}
Preview
Hello World!

Powerful Features for Modern Development

Everything you need to build interactive coding experiences, online IDEs, and educational platforms.

Monaco Editor Integration

Powered by the same editor that powers VS Code, with syntax highlighting, IntelliSense, and advanced editing features.

Live Preview

Real-time preview of your code with automatic updates as you type. See changes instantly without manual refresh.

File Management

Complete file system with create, edit, delete, and rename operations. Organize your project files with ease.

Integrated Terminal

Built-in terminal with console output, network monitoring, and command execution capabilities.

Dependency Management

Smart dependency detection and management with CDN integration and package installation.

High Performance

Optimized for speed with efficient rendering, minimal re-renders, and smooth user experience.

Customizable Themes

Dark and light themes with customizable styling options to match your application design.

TypeScript Support

Full TypeScript support with type definitions and excellent developer experience.

Responsive Design

Fully responsive design that works perfectly on desktop, tablet, and mobile devices.

Ready to Get Started?

Join thousands of developers who are already using React Playground Editor to build amazing interactive coding experiences.

See It In Action

Experience the power of React Playground Editor with our interactive demo. Try editing the code and see the live preview update in real-time.

React Playground Editor Demo
Live
Files
📁src/
📄App.jsx
📄index.js
📄styles.css
Editor
import React, { useState } from 'react'

function App() {
  const [count, setCount] = useState(0)

  return (
    <div className="app">
      <h1>Hello React!</h1>
      <p>Count: {count}</p>
      <button onClick={() => setCount(count + 1)}>
        Increment
      </button>
    </div>
  )
}
Preview

Hello React!

Count: 0

Quick Installation

Get started with React Playground Editor in minutes. Install the package and start building interactive coding experiences.

Install the Package

npm
npm install react-playground-editor
yarn
yarn add react-playground-editor
pnpm
pnpm add react-playground-editor
1

Install Dependencies

Install the package using your preferred package manager. The library includes all necessary peer dependencies.

2

Import CSS

Import the CSS file to get the default styling and themes.

import 'react-playground-editor/dist/index.css'
3

Use the Component

Import and use the Playground component in your React application.

import { Playground } from 'react-playground-editor'

Peer Dependencies

Make sure you have these peer dependencies installed in your project:

react@^18.0.0
react-dom@^18.0.0
zustand@^4.0.0
lucide-react@^0.400.0

Usage Examples

Learn how to integrate React Playground Editor into your applications with these practical examples.

Basic Usage

import React from 'react';
import { Playground } from 'react-playground-editor';
import 'react-playground-editor/dist/index.css';

function App() {
  const initialFiles = {
    'src/App.jsx': `import React from 'react';

function App() {
  return (
    <div>
      <h1>Hello React!</h1>
      <p>Start editing to see some magic happen!</p>
    </div>
  );
}

export default App;`,
    'src/index.js': `import React from 'react';
import ReactDOM from 'react-dom/client';
import App from './App';

const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<App />);`
  };

  return (
    <div style={{ height: '100vh' }}>
      <Playground
        initialFiles={initialFiles}
        defaultActiveFile="src/App.jsx"
        showFileExplorer={true}
        showTerminal={true}
        showWebView={true}
        showDependencies={true}
        theme="dark"
      />
    </div>
  );
}

export default App;

Advanced Usage with Event Handlers

import React from 'react';
import { Playground, useFileStore } from 'react-playground-editor';
import 'react-playground-editor/dist/index.css';

function AdvancedPlayground() {
  const handleFileChange = (files) => {
    console.log('Files changed:', files);
    // Save files to localStorage, send to server, etc.
  };

  const handleActiveFileChange = (filePath) => {
    console.log('Active file changed:', filePath);
  };

  return (
    <div style={{ height: '100vh' }}>
      <Playground
        initialFiles={{
          'src/App.jsx': `import React, { useState } from 'react';

function App() {
  const [count, setCount] = useState(0);

  return (
    <div style={{ padding: '20px' }}>
      <h1>Counter App</h1>
      <p>Count: {count}</p>
      <button onClick={() => setCount(count + 1)}>
        Increment
      </button>
    </div>
  );
}

export default App;`,
          'src/styles.css': `body {
  font-family: Arial, sans-serif;
  margin: 0;
  padding: 0;
}

button {
  background: #007bff;
  color: white;
  border: none;
  padding: 10px 20px;
  border-radius: 4px;
  cursor: pointer;
}

button:hover {
  background: #0056b3;
}`
        }}
        defaultActiveFile="src/App.jsx"
        showFileExplorer={true}
        showTerminal={true}
        showWebView={true}
        showDependencies={true}
        theme="dark"
        onFileChange={handleFileChange}
        onActiveFileChange={handleActiveFileChange}
        className="custom-playground"
        style={{ border: '1px solid #e5e7eb' }}
      />
    </div>
  );
}

export default AdvancedPlayground;
💡

Initial Files

Provide initial files as a key-value object where keys are file paths and values are file contents.

🎨

Customization

Customize the appearance with themes, show/hide panels, and add custom styling with className and style props.

Event Handling

Listen to file changes and active file changes to implement auto-save, persistence, or other custom behaviors.

API Reference

Complete reference for all props and methods available in React Playground Editor.

TypeScript Interface

interface PlaygroundProps {
  // Initial files to load
  initialFiles?: Record<string, string>;
  
  // Default active file
  defaultActiveFile?: string;
  
  // Panel visibility controls
  showFileExplorer?: boolean;
  showTerminal?: boolean;
  showWebView?: boolean;
  showDependencies?: boolean;
  
  // Theme
  theme?: "dark" | "light";
  
  // Event handlers
  onFileChange?: (files: Record<string, string>) => void;
  onActiveFileChange?: (filePath: string) => void;
  
  // Styling
  className?: string;
  style?: React.CSSProperties;
}

Props

PropTypeRequiredDescriptionExample
initialFilesRecord<string, string>OptionalObject containing initial files where keys are file paths and values are file contents.{ 'src/App.jsx': 'import React from "react";...' }
defaultActiveFilestringOptionalPath of the file that should be active by default."src/App.jsx"
showFileExplorerbooleanOptionalWhether to show the file explorer panel.true
showTerminalbooleanOptionalWhether to show the terminal panel.true
showWebViewbooleanOptionalWhether to show the web view panel.true
showDependenciesbooleanOptionalWhether to show the dependencies panel.true
theme"dark" | "light"OptionalTheme for the playground interface."dark"
onFileChange(files: Record<string, string>) => voidOptionalCallback function called when files are modified.(files) => console.log(files)
onActiveFileChange(filePath: string) => voidOptionalCallback function called when the active file changes.(filePath) => console.log(filePath)
classNamestringOptionalAdditional CSS class names for the playground container."custom-playground"
styleReact.CSSPropertiesOptionalInline styles for the playground container.{ height: "100vh" }

📚 Documentation

For more detailed documentation and examples, visit our GitHub repository.

View Documentation →

🐛 Issues & Support

Found a bug or need help? Open an issue on GitHub or start a discussion.

Get Support →