Skip to main content

Hooks API

These functions provide Hooks for accessing the ambient Player and subscribing to certain events. They are exported from the root of the library.

import {useMarkerUpdate, usePlayer, useTimeUpdate} from "ractive-player";

useMarkerUpdate()#

Subscribe to the markerupdate event of Script. Callback receives the index of the previous marker (the current index can be accessed via Script.markerIndex). The second argument is an array of dependencies used to avoid resubscriptions; you will usually want to pass [].

useMarkerUpdate(callback: (prevIndex: number) => void, deps?: React.DependencyList): void;

usePlayer()#

Access the ambient Player.

usePlayer(): Player;

useTimeUpdate()#

Subscribe to the timeupdate event of Playback. Callback receives the current time in milliseconds. The second argument is an array of dependencies used to avoid resubscriptions; you will usually want to pass [].

useTimeUpdate(callback: (t: number) => void, deps?: React.DependencyList): void;