Skip to content

useCanvasContext

Read as Markdown

import { useCanvasContext } from "@pibbl/core";

useCanvasContext() returns RenderingContext2D and is render-only: call it synchronously from a Pibbl component while it is rendering, never from pure measurement or an event callback. Pibbl isolates Canvas state around component traversal; do not retain the context for later work.

function Marker() {
const context = useCanvasContext();
context.fillRect(0, 0, 8, 8);
}

Use a public drawing component where possible; custom Canvas work belongs in a custom component or primitive.

Returns the current component’s isolated Canvas 2D context.

useCanvasContext: () => RenderingContext2D

Related API: useCanvasContext, RenderingContext2D.

The active Canvas 2D rendering context for this component evaluation. See RenderingContext2D .

RenderingContext2D

View source — packages/core/src/lib/hooks/use-canvas-context.ts:16

Read the Drawing, layout, and effects companion for ownership, adaptation, failure modes, and verification. Agent start provides the version-selection workflow.

Documentation built with @pibbl/core 0.0.2, revision 380919b. ALPHA — NOT FOR PRODUCTION USE.