Skip to content
Skip to content
Web playback

Use Chorono with React

Mount the published JavaScript runtime inside a React component. This guide uses @chorono/runtime 0.1.0; there is no separate React SDK to install for this example.

Prepare the scene#

Follow JavaScript installation. Download the title-card runtime JSON and serve it from your app's public directory as /animation.runtime.json.

Mount and clean up the player#

This client component loads the package inside its effect, aborts stale requests and destroys its owned player on unmount. A new src replaces the player; effect cleanup also handles React's development remount checks.

'use client'

import { useEffect, useRef, useState } from 'react'
import type { ChronoPlayer } from '@chorono/runtime'

export function ChoronoAnimation({ src = '/animation.runtime.json' }) {
  const canvas = useRef<HTMLCanvasElement>(null)
  const player = useRef<ChronoPlayer | null>(null)
  const [status, setStatus] = useState('Loading animation…')
  const [ready, setReady] = useState(false)

  useEffect(() => {
    const controller = new AbortController()
    let owned: ChronoPlayer | undefined
    setReady(false)
    setStatus('Loading animation…')

    async function load() {
      try {
        const [{ ChronoPlayer, CanvasRenderAdapter }, response] = await Promise.all([
          import('@chorono/runtime'),
          fetch(src, { signal: controller.signal }),
        ])
        if (!response.ok) throw new Error('Scene could not load')
        const exported = await response.json()
        if (controller.signal.aborted || !canvas.current) return
        const context = canvas.current.getContext('2d')
        if (!context) throw new Error('Canvas 2D is unavailable')
        canvas.current.width = exported.runtime.composition.width
        canvas.current.height = exported.runtime.composition.height
        owned = new ChronoPlayer(exported.runtime, new CanvasRenderAdapter(context), { loop: true })
        player.current = owned
        owned.seek(0)
        setStatus('Ready')
        setReady(true)
      } catch (error) {
        if (!controller.signal.aborted) setStatus(String(error))
      }
    }
    void load()
    return () => {
      controller.abort()
      owned?.destroy()
      if (player.current === owned) player.current = null
    }
  }, [src])

  return <figure>
    <canvas ref={canvas} aria-label="Chorono animation" style={{ width: '100%', height: 'auto' }} />
    <figcaption role="status">{status}</figcaption>
    <button disabled={!ready} onClick={() => player.current?.play()}>Play</button>
    <button disabled={!ready} onClick={() => player.current?.pause()}>Pause</button>
  </figure>
}

Adapt it to your application#

Playback starts only when the visitor chooses Play. Keep controls accessible and pause the player when your application hides the view. Review export warnings before shipping; the example loads a reviewed, media-free scene.

For player methods and host-supplied assets, continue with the JavaScript runtime. Use runtime JSON export for your own scene and keep its editable project separately.

A good place to start
Getting started / Chorono documentationChorono documentationLearn Chorono with editable animation examples. Install the editor, edit keyframes, build loops and connect Claude Code or Codex through MCP. Cre…Getting started / Install ChoronoInstall ChoronoSet up the free, open-source animation editor on your computer and start a local browser session. This guide installs the browser editor, its loc…Getting started / Create your first editable animationCreate your first editable animationOpen an editable Chorono example, change its text and colors, inspect the timeline, then save and reopen your first 2D animation. Start with a re…Workspace / Chorono editor workspaceChorono editor workspaceFind the canvas, layers, properties, timeline and resource tools in the Chorono editor. Choose a guide for each part of your animation workflow.…Workspace / Canvas and drawing toolsCanvas and drawing toolsNavigate the canvas, draw shapes and splines, use snapping and edit motion keys in Chorono. Use the canvas to arrange the objects in your composi…Workspace / Choose a drawing or transform toolChoose a drawing or transform toolUse Select, Pan, Pen, Move, Rotate, Scale and Anchor tools without losing track of the active editing mode. Choose the tool that matches the edit…Workspace / Select exactly the objects you needSelect exactly the objects you needUse box, lasso, circle, paint and rule-based selection to work with several animation layers. When several objects overlap, clicking each one can…Workspace / Align objects with guides and snappingAlign objects with guides and snappingSet grid, object, point, guide, pixel, angle and scale snapping for precise placement in Chorono. Snapping helps a dragged object settle on an ex…Workspace / Edit Bézier points and spline curvesEdit Bézier points and spline curvesDraw editable paths, adjust points and handles, and extend or close a spline in Chorono. A curve is easier to control when you can see the points…Workspace / Edit animation positions on the canvasEdit animation positions on the canvasUse Motion Keys to adjust position keys, draw a movement and control how the path is timed. Motion Keys bring position editing onto the canvas. T…Workspace / Layers and scene hierarchyLayers and scene hierarchySelect, name, group and organize scene objects in Chorono using the Layers panel and Scene Explorer. A layer is an editable object in your Choron…Workspace / Draw and edit basic shapesDraw and edit basic shapesCreate rectangles, circles, polygons and procedural shapes, then adjust their geometry in Properties. Basic shapes are a useful starting point fo…
Explore the docs