UNPKG

react-code-canvas

Version:

A browser-based canvas for rendering React components at runtime

22 lines (21 loc) 980 B
import { Scope } from './types'; export type ResolvedScope = { /** the scope to evaluate `readyCode` against; undefined until the first resolve */ scope: Scope | undefined; /** the code whose dependencies have finished loading */ readyCode: string; }; /** * Resolves the scope the given code needs, asynchronously. * * Returns `readyCode` rather than a boolean flag so the caller can only ever * evaluate code whose scope is actually loaded. Before the first resolve that * is `''`, which evaluates to nothing and lets the loading overlay show. On a * later code change the previous code keeps rendering until the new scope * arrives, so typing in the editor never blanks the preview or flashes a * ReferenceError for an icon that is still in flight. * * Already-loaded modules resolve in a microtask, so steady-state editing costs * one tick, not a round trip. */ export declare const useResolvedScope: (code: string, extra?: Scope) => ResolvedScope;