@threlte/theatre

useSequence

The useSequence hook allows you to access a sequence’s playback controls using a store API.

Usage

The hook can be used within the <Sheet> context or withing the <Sequence> context:

<!-- child of a <Sheet> or <Sequence> -->
<script lang="ts">
  import { useSequence } from '@threlte/theatre'
  const { position, playing, length, play, pause, config } = useSequence()
</script>

Example

This example uses the useSequence hook to allow you to control the feather’s animation using the feather itself. Hover will pause the animation and clicking and dragging the feather up and down allow you to wind back and forth in time.

Output

The following values are returned by the hook:

storetypedescription
lengthnumberThe length of the sequence, which is set within the studio
positionWritable<number>The sequence playhead position
playingWritable<boolean>The sequence state (playing or paused)
play(opts?: SequenceOptions) => Promise<boolean>Method for playing the sequence
pause() => voidMethod for pausing the sequence
config(opts: SequenceOptions) => voidMethod for updating the sequence’s options