sandpack icon indicating copy to clipboard operation
sandpack copied to clipboard

Sandpack Provider without using a template

Open jamesmurdza opened this issue 2 years ago • 2 comments

Discussed in https://github.com/codesandbox/sandpack/discussions/970

Originally posted by jamesmurdza July 15, 2023 If I remove, template="static" from the below code, the template is still applied. I want to provide my own directory structure with a completely different list of files. How can I do this?

import './App.css'
import { SandpackProvider, SandpackLayout, SandpackPreview, SandpackConsole } from "@codesandbox/sandpack-react";

export default function App() {
  const files = {}

  return (
    <SandpackProvider
      files={files}
      theme="light"
      template="static"
    >
      <SandpackLayout>
        <SandpackPreview />
        <SandpackConsole />
      </SandpackLayout>
    </SandpackProvider>
  )
}
```</div>

jamesmurdza avatar Aug 01 '23 13:08 jamesmurdza

Try this

      <SandpackProvider
        theme="auto"
        files={{
          '/user.sql': `CREATE TABLE users (
  id INTEGER PRIMARY KEY AUTOINCREMENT,
  name TEXT NOT NULL,
  age INTEGER NOT NULL
);
`,
        }}
        customSetup={{
          entry: '/user.sql',
        }}
      >
      <SandpackLayout>
        <SandpackPreview />
        <SandpackConsole />
      </SandpackLayout>
    </SandpackProvider>

husniramdani avatar Sep 03 '24 11:09 husniramdani

Try this

  <SandpackProvider
    theme="auto"
    files={{
      '/user.sql': `CREATE TABLE users (

id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT NOT NULL, age INTEGER NOT NULL ); `, }} customSetup={{ entry: '/user.sql', }} > <SandpackLayout> <SandpackPreview /> <SandpackConsole /> </SandpackLayout> </SandpackProvider>

with "@codesandbox/sandpack-react": "^2.20.0", a package.json is still involved:

Image

wymli avatar Nov 09 '25 10:11 wymli