React Live is a versatile library for creating interactive, live-editable React code playgrounds within web applications. It allows developers to render React components dynamically, display their editable source code, and provide a real-time preview of the changes. The current stable version is 4.1.8, with patch releases occurring frequently to address fixes and minor improvements, as seen in recent version bumps (e.g., 4.1.0 to 4.1.8). Key differentiators include its modular structure, allowing for flexible styling and composition of its core components (`LiveProvider`, `LiveEditor`, `LiveError`, `LivePreview`), and its focus on being production-ready. It abstracts the complexities of code compilation and error handling, making it suitable for documentation sites, component libraries, and interactive learning platforms.
npm install react-liveVerified import paths — ran on the pinned version, not inferred.
Demonstrates setting up a basic live code playground with an editable editor, a real-time preview, and error display using `react-live` components.
Review the Prism React Renderer v2 documentation and adjust any custom rendering logic or styling accordingly. Most users relying on `react-live`'s high-level components should not be heavily impacted.
Update your project's `react` and `react-dom` packages to version `18.0.0` or newer. Ensure all other React-related dependencies are compatible with React 18.
Ensure `scope` includes all necessary React hooks (e.g., `React.useState`, `React.useEffect`), components, or other variables required by the code. For example, `scope={{ React, useState: React.useState }}`.Always ensure the code passed to `LiveProvider`'s `code` prop ultimately calls `render()` with a single, valid React element (e.g., `render(<div>Hello</div>)` or `render(<MyComponent />)`).
Pass `React` into the `scope` prop: `<LiveProvider code={code} scope={{ React }}>`Ensure `React.useState`, `React.useEffect`, etc., are provided in the `scope` if used directly, or properly destructure them: `<LiveProvider code={code} scope={{ React, useState: React.useState }}>`Ensure `react-live` is updated to the latest patch version, as `v4.1.7` specifically fixed optional chaining with Sucrase. If the issue persists with custom transpilers or specific configurations, check their documentation for feature support.