Components

CodesparkProvider

Context provider that shares workspace state and configuration across child components.

CodesparkProvider is a context provider that shares workspace state and configuration across child components. Use it when building custom layouts with CodesparkEditor, CodesparkPreview, and CodesparkFileExplorer.

import { CodesparkProvider } from '@codespark/react';

When to Use

The all-in-one Codespark component already includes a provider internally. You only need CodesparkProvider when:

  • Building a custom layout with separate editor and preview components
  • Sharing workspace state across multiple components
  • Creating advanced integrations with custom UI

Basic Usage

<CodesparkProvider>
  <CodesparkEditor />
  <CodesparkPreview />
</CodesparkProvider>

Props

workspace

Workspace instance to use for file management and compilation.

TypeDefaultSince
WorkspaceAuto-createdv1.0.0

If not provided, a default workspace is created with an empty ./App.tsx file.

import { ,  } from '@codespark/react';

const  = new ({
  : './App.tsx',
  : { './App.tsx': 'export default () => <div>Hello</div>' }
});

< ={}>
  {/* children */}
</>

theme

Theme mode for the editor and preview.

TypeDefaultSince
'light' | 'dark''light'v1.0.0
< ="dark">
  {/* children */}
</>

framework

Framework to use for code analysis and compilation.

TypeDefaultSince
Framework | (new () => Framework) | string-v1.0.0
import {  } from '@codespark/framework/html';
import {  } from '@codespark/react';

< ={}>
  {/* children */}
</>

imports

Custom import map for external dependencies.

TypeDefaultSince
Record<string, string>-v1.0.0
< ={{ 'lodash-es': 'https://esm.sh/lodash-es@4.17.21' }}>
  {/* children */}
</>

editor

Default editor engine component to use (Monaco or CodeMirror).

TypeDefaultSince
typeof Monaco | typeof CodeMirrorCodeMirrorv1.0.0
import {  } from '@codespark/react';
import {  } from '@codespark/react/Monaco';

< ={}>
  {/* children */}
</>

children

Child components that will receive the workspace context.

TypeDefaultSince
ReactNode-v1.0.0

Layouts

Vertical Layout

Horizontal Layout

Tabbed Layout

Last updated on