API Reference

React

The shaderpad/react entry exports:

import ShaderPad, { type ShaderPadProps } from 'shaderpad/react';

If you want the usage patterns first, start with Components / React.

Exports

ExportTypeMeaning
defaultcomponentReact wrapper that renders one managed <canvas>.
ShaderPadcomponentAlias for the default export.
ShaderPadPropstypeProp type for the component.

Props

Required

PropTypeMeaning
shaderstringFragment shader source.

Core Configuration

PropTypeDefaultMeaning
pluginsPlugin[][]Additional plugins to install after wrapper-owned autosize.
optionsOmit<Options, 'canvas' | 'plugins' | 'cursorTarget'>{}Core constructor options other than wrapper-owned canvas, plugins, and cursor target.
autosizeboolean | AutosizeOptionstrueEnables wrapper-owned autosize() or passes custom autosize options.
cursorTargetWindow | Element | RefObject<Element | null>canvas element when applicableTarget for built-in pointer uniforms. Ref targets delay initialization until resolved.

Playback

PropTypeDefaultMeaning
autoplaybooleantrueStarts playback automatically after initialization.
autopausebooleantruePauses autoplay when offscreen or document-hidden, then resumes when visible again.

Callbacks

PropTypeMeaning
onInit(shader, canvas) => voidRuns after setup, before autoplay starts.
onPreStep(shader, time, frame) => StepOptions | voidRuns whenever the underlying ShaderPad emits preStep. Returned step options apply to frames started through the component.
onError(error) => voidReceives constructor/setup errors instead of letting them surface as uncaught runtime errors.

Texture Children

ShaderPadProps allows children for declarative texture sources:

<ShaderPad shader={shader}>
  <img data-texture="u_image" src="/image.png" alt="" />
  <video data-texture="u_video" src="/video.mp4" muted playsInline />
  <canvas data-texture="u_canvas" width={512} height={512} />
  <ShaderPad shader={passShader} data-texture="u_pass" />
</ShaderPad>

Texture option props map onto initializeTexture():

PropMeaning
data-texture-historyTexture history depth.
data-texture-preserve-yPreserves or flips source Y.
data-texture-internal-formatWebGL internal texture format.
data-texture-formatWebGL texture format.
data-texture-typeWebGL texture type.
data-texture-min-filterWebGL minification filter.
data-texture-mag-filterWebGL magnification filter.
data-texture-wrap-sWebGL horizontal wrap mode.
data-texture-wrap-tWebGL vertical wrap mode.
data-texture-color-spaceTexture color space.

Canvas Props

ShaderPadProps extends normal React canvas props, like className and aria-label, except the DOM onError.

Default inline style values:

  • display: 'block'
  • width: '100%'
  • height: '100%'

Your style prop is merged on top of those defaults.

Events

To add events listeners, subscribe through the underlying ShaderPad instance:

const ref = useRef<React.ElementRef<typeof ShaderPad>>(null);

useEffect(() => {
  const shader = ref.current?.shader;
  if (!shader) return;

  const handleResize = (width: number, height: number) => {};
  shader.on('autosize:resize', handleResize);
  return () => shader.off('autosize:resize', handleResize);
}, [ready]);

Core event signatures are documented on the main Events page.

Ref API

The component uses forwardRef. The public way to type the ref is:

const ref = useRef<React.ElementRef<typeof ShaderPad>>(null);

The ref exposes the managed canvas, the underlying core shader, and the same playback methods documented on the ShaderPad API page.

Runtime Behavior

The wrapper keeps callback props and playback props live without recreating the instance. By default, it starts playing after setup and pauses autoplay while the canvas is not visible.

Behavior by prop combination:

autoplayautopauseBehavior
truetruePlay when visible, pause autoplay when not visible.
truefalseStart after init and keep running until user code pauses it.
falseeitherNever auto-start.

autopause only affects automatic playback started by the component. If you call play() yourself, pausing and resuming that loop is up to your code.

Rules

  • Use this component only from client components in frameworks such as Next.js.
  • Do not pass your own autosize() plugin in plugins unless you also set autosize={false}.
  • Use onInit, onPreStep, or the ref for dynamic uniform and texture work.