Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom files without using Sandpack #78

Closed
gdimitropoulos opened this issue Aug 2, 2021 · 2 comments
Closed

Custom files without using Sandpack #78

gdimitropoulos opened this issue Aug 2, 2021 · 2 comments

Comments

@gdimitropoulos
Copy link

Trying to follow the example

  SandpackProvider,
  SandpackLayout,
  SandpackCodeEditor,
  SandpackPreview,
} from "@codesandbox/sandpack-react";

const CustomSandpack = () => (
  <SandpackProvider template="react">
    <SandpackLayout>
      <SandpackCodeEditor />
      <SandpackPreview />
    </SandpackLayout>
  </SandpackProvider>
);

I was't able to find a way to insert custom files to the initiated sandbox and could not find an example on docs.
Is there a way of initiate the sandbox with my custom files while using this setup?

@danilowoz
Copy link
Member

Hey @GeorgeDimCeid, thanks for opening this issue. We know that our documentation still is not that good, and we're looking forward to improving it. That's why it's so important to know when you don't find in the documentation what you're looking for.

So basically, you can use the customSetup prop which is a SandpackSetup type that supports the files options.

const CustomSandpack = () => (
  <SandpackProvider 
    template="react" 
    customSetup={{
        files: {
            "/App.js": code,
        },
    }}>
    <SandpackLayout>
      <SandpackCodeEditor />
      <SandpackPreview />
    </SandpackLayout>
  </SandpackProvider>
);

@gdimitropoulos
Copy link
Author

gdimitropoulos commented Aug 11, 2021

I was wondering if you can pass your whole project folder or to be shown inside the sandpack instance via the files prop
image
can anyone show me an example?
@danilowoz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants