Hooks & commands
The editor exposes its Zustand store via hooks. For reads, call useEditor(selector) — it subscribes only to the slice you pick. For writes that should be undoable, dispatch commands instead of calling setState directly.
Reading state
import { useEditor } from '@videoflow/react-video-editor';
function LayerCount() {
const count = useEditor((s) => s.video.layers.length);
return <span>{count} layers</span>;
}| Hook | Returns |
|---|---|
useEditor(selector) | Memoised slice of the store. |
useVideo() | The current VideoJSON. |
useSelection() | { ids: string[], layers: LayerJSON[] } — selected ids and the resolved layers. |
usePlayhead() | { frame, playing } — current frame and play state. |
useViewport() | Timeline zoom / scroll state. |
useHistoryState() | { canUndo, canRedo }. |
useActiveLayers() | LayerJSON[] — layers currently in scope (respects the active group context). |
useActiveGroup() | LayerJSON | null — the group the user has drilled into. |
useActiveGroupChain() | LayerJSON[] — full ancestor chain of the active group. |
useActiveGroupPath() | string[] — the active group ids, root-to-leaf. |
useEditorStore() | Raw Zustand store for escape hatches. |
Commands
A command is a pure function that returns an Immer patch plus metadata. Dispatching a command pushes a history entry (undoable, merge-aware) and triggers onChange.
import { useEditorStore, commands } from '@videoflow/react-video-editor';
function NudgeRight() {
const dispatch = useEditorStore((s) => s.dispatch);
return (
<button onClick={() => dispatch(commands.moveLayersCommand({ ids, dx: 10 }))}>
Move right 10px
</button>
);
}Available commands
| Command | Use for |
|---|---|
addLayerCommand | Insert a layer. |
removeLayersCommand | Delete one or more layers. |
reorderLayersCommand | Change stacking / track order. |
moveLayersCommand | Translate by dx / dy. |
resizeLayerCommand | Change width / height. |
trimStartCommand | Trim a clip's start. |
setPropertyCommand | Set any layer property. |
unsetPropertyCommand | Reset to default. |
setSettingCommand | Patch project settings. |
setLayerEnabledCommand | Toggle a layer on/off. |
set3DTransformCommand | Set 3D translate / rotate. |
setKeyframeCommand / removeKeyframeCommand | Edit keyframes. |
setTransitionCommand | Swap transitionIn / Out. |
addEffectCommand / removeEffectCommand / moveEffectCommand | Manage effects stack. |
setEffectParamCommand | Patch one effect param. |
setProjectSettingsCommand | Patch the project metadata. |
setTrackSettingsCommand | Patch per-track metadata. |
History model
- Up to 200 entries retained per session.
- Merges within an 800 ms window — rapid inputs collapse into one undo step.
- Cmd+Z / Cmd+Shift+Z hooked up automatically.
Renderer bridge
For advanced programmatic control, reach the underlying DomRenderer via state.bridge:
const { bridge } = useEditorStore.getState();
await bridge.seek(120);
await bridge.renderFrame(120);