New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@codesandbox/sandpack-react

Package Overview
Dependencies
Maintainers
0
Versions
385
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@codesandbox/sandpack-react

  • 2.20.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
177K
increased by3.47%
Maintainers
0
Weekly downloads
 
Created

What is @codesandbox/sandpack-react?

@codesandbox/sandpack-react is a React component library that allows you to embed and run code sandboxes directly in your React applications. It provides a seamless way to integrate live code editing and previewing experiences, making it ideal for documentation, tutorials, and interactive coding environments.

What are @codesandbox/sandpack-react's main functionalities?

Basic Setup

This code demonstrates the basic setup of a Sandpack component with a simple React template. It includes a single file, `App.js`, which renders a 'Hello, world!' message.

import { Sandpack } from '@codesandbox/sandpack-react';

function App() {
  return (
    <Sandpack
      template="react"
      files={{
        '/App.js': `import React from 'react';
        
        export default function App() {
          return <h1>Hello, world!</h1>;
        }`
      }}
    />
  );
}

Custom Themes

This code demonstrates how to apply a custom theme to the Sandpack component. In this example, the 'dracula' theme is applied to the same basic React template.

import { Sandpack } from '@codesandbox/sandpack-react';
import { dracula } from '@codesandbox/sandpack-themes';

function App() {
  return (
    <Sandpack
      template="react"
      theme={dracula}
      files={{
        '/App.js': `import React from 'react';
        
        export default function App() {
          return <h1>Hello, world!</h1>;
        }`
      }}
    />
  );
}

Multiple Files

This code demonstrates how to include multiple files in a Sandpack component. The `App.js` file imports and uses a `Hello` component defined in `Hello.js`.

import { Sandpack } from '@codesandbox/sandpack-react';

function App() {
  return (
    <Sandpack
      template="react"
      files={{
        '/App.js': `import React from 'react';
        import { Hello } from './Hello';
        
        export default function App() {
          return <Hello />;
        }`,
        '/Hello.js': `import React from 'react';
        
        export function Hello() {
          return <h1>Hello, world!</h1>;
        }`
      }}
    />
  );
}

Other packages similar to @codesandbox/sandpack-react

FAQs

Package last updated on 14 Feb 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc