React
import { useRef } from "react";import { TICKS_PER_SECOND as hz, shallowEqual } from "@lumen-timeline/core";import { Timeline, TimelineProvider, useEditorSelector, useTimelineContext, useTransportSelector,} from "@lumen-timeline/react";import "@lumen-timeline/timeline/style.css";
function TakeInspector() { const { editor } = useTimelineContext(); const clip = useEditorSelector( editor, ({ snapshot, selection }) => { const found = snapshot.clips.find((c) => c.id === selection.at(-1)); return found ? { id: found.id, name: found.name, take: found.activeTakeId } : null; }, shallowEqual, ); return <aside>{clip ? `${clip.name}: ${clip.take}` : "No clip selected"}</aside>;}
function Clock() { const { transport } = useTimelineContext(); const tenths = useTransportSelector(transport, (s) => Math.floor(s.presentedTick / (hz / 10))); return <output>{(tenths / 10).toFixed(1)} s</output>;}
export function Workspace({ editor, transport, tiles }) { const view = useRef(null); return ( <TimelineProvider editor={editor} transport={transport}> <Clock /> <Timeline editor={editor} transport={transport} waveforms={tiles} snap={{ gridTicks: hz / 10 }} ref={view} /> <TakeInspector /> </TimelineProvider> );}<Timeline {...options}>renders adivand mounts the view in it from a layout effect. It takes everymountTimelineoption as a prop, withclassNameandstylefor thediv.refreceives theTimelineView, forreveal,setViewportorhitTest, andnullonce it is disposed.useEditorSelector(editor, select, isEqual)returns a field of the editor’s state throughuseSyncExternalStore. The selector may be written inline. A new selection equal to the one on screen keeps that one’s identity, so the component renders only whenisEqualfinds a change.useTransportSelector(transport, select, isEqual)does the same for any source withsnapshot()andsubscribe(). A transport notifies on every frame during playback, so select no finer a field than the panel shows.<TimelineProvider editor transport>anduseTimelineContext()hand the host’s editor and transport to panels below it.useTimelineContextthrows without a provider.- Under
StrictModein development, React mounts each new component’s effects twice. The first view is disposed at once, before anything draws.