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
4
Versions
385
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@codesandbox/sandpack-react

2.19.10
Source
npm
Version published
Weekly downloads
143K
-18.65%
Maintainers
4
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 21 Nov 2024

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