Skip to content

StudioProvider

The editor context provider that sets up the editor state tree. It must be wrapped by SessionProvider, which handles session validation.

Usage

tsx
import {
  StudioProvider,
  SessionProvider,
  SessionResponse,
} from "@asset-studio/core";

async function createSession(userGuid: string): Promise<SessionResponse> {
  const response = await fetch("https://your-server.com/createSession", {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify({ user_guid: userGuid }),
  });
  return response.json();
}

export default function App() {
  return (
    <SessionProvider onCreateSession={createSession}>
      <StudioProvider>
        {/* Studio, Asset, or any component using hooks */}
      </StudioProvider>
    </SessionProvider>
  );
}

Props

PropTypeRequiredDescription
childrenReactNodeYesYour editor components and any components using Asset Studio hooks.
initialWidthnumberNoInitial canvas width in pixels. Defaults to 1080.
initialHeightnumberNoInitial canvas height in pixels. Defaults to 1080.
onSaveDrawShape(shape: ShapeDrawItemType) => voidNoCalled when the user saves a drawn shape.
errorFallbackReactNodeNoUI to render if session validation fails.

Behavior

  • Session validation is handled by the wrapping SessionProvider. See Session Setup.
  • All hooks (useStudio, usePlayer, etc.) must be called from components inside this provider.
  • Calling a hook outside of StudioProvider will throw an error.

Notes

  • You only need one StudioProvider per editor instance.
  • The provider is lightweight and does not render any visible UI itself.
  • It is safe to place it high in your component tree (e.g. at the app root) if you use a single editor instance.

Released under a proprietary license.