MotionHooks
Remotion timing hooks in seconds: elapsed time, a spring entrance, a cubic-out fade, and an eased progress value.
Loading preview…
Install
npx shadcn@latest add @jbm/motion-hooksNeeds the @jbm entry in components.json; see Install once.
Needs Remotion: render inside a Remotion <Composition> or <Player>, not a plain React tree. Timing values are in seconds.
Usage
import { useSec, useIn, useFade, useProgress } from "@/jbm/motion/hooks"// Render inside a Remotion <Composition> or <Player>: hooks run in the component body.export function TimelineReadout() { const seconds = useSec() const entrance = useIn(0.2) const opacity = useFade(0.2) const progress = useProgress(0.2, 100, 1.5) return ( <div style={{ opacity, transform: `translateY(${(1 - entrance) * 30}px)` }}> {progress.toFixed(0)}% at {seconds.toFixed(2)}s </div> )}API
- Stage
n/aHooks only; they render nothing. The gallery preview is a demo component built on them.
useSechook
Seconds elapsed since the start of the enclosing Remotion Sequence (current frame ÷ fps).
No params.
Returns Elapsed seconds as a number; fractional between frames.
useInhook
Spring entrance that starts at startSec (rounded to the nearest frame) with mass 0.8. Stays 0 before the start and settles near 1; it can overshoot 1 slightly while settling.
| Param | Type | Default | Description |
|---|---|---|---|
startSec | number | required | Start time in seconds relative to the enclosing Sequence. |
opts | { damping?: number; stiffness?: number } | none | Optional spring config: damping (default 14) and stiffness (default 120). Lower damping bounces more. |
Returns Spring value from 0 toward 1, for opacity, scale, or translate progress.
useFadehook
Cubic-out interpolation from 0 to 1 over dur seconds starting at startSec, clamped at both ends.
| Param | Type | Default | Description |
|---|---|---|---|
startSec | number | required | Start time in seconds relative to the enclosing Sequence. |
dur | number | 0.4 | Fade length in seconds. |
Returns Opacity-style value clamped to 0–1.
useProgresshook
Cubic-out interpolation from 0 to target over dur seconds starting at startSec, clamped at both ends. Use for bar fills, counters, and draw-on strokes.
| Param | Type | Default | Description |
|---|---|---|---|
startSec | number | required | Start time in seconds relative to the enclosing Sequence. |
target | number | 1 | Value reached at startSec + dur and held afterwards (e.g. 1, 100, or a probability). |
dur | number | 0.7 | Seconds taken to reach target. |
Returns Number between 0 and target.
QA checks
- Step to the first frame, the middle of the 1.5 s window, and the last frame: the percentage reads 0, an intermediate value, then exactly 100; useSec matches frame ÷ fps.
- Check that times are relative to the enclosing Sequence: a component inside a Sequence that starts later still enters at its own
startSec. - When changing spring defaults, re-check every consumer (Pop, ProbBar, RebuildScreens, Catalog) and the gallery preview durations measured from the same spring config.