# getActiveTextCues

The cues active now on the text tracks a filter or track definition matches

## Import

```tsx
import { getActiveTextCues } from '@videojs/react';
```

`getActiveTextCues` returns the cues active at the current time on the tracks a filter or [track definition](https://videojs.org/docs/framework/react/reference/api/define-text-track) matches, from the media and the app alike. Cues from several tracks are merged in time order.

It reads `textCues` from the [text cues feature](https://videojs.org/docs/framework/react/reference/api/feature-text-cues), which describes when a cue is active, so it only finds cues on the tracks that feature reads.

Read through a definition, cues are typed by it. With a schema, cues whose value fails it are skipped.

## Usage

In a component, [`useActiveTextCues`](https://videojs.org/docs/framework/react/reference/api/use-active-text-cues) re-renders when the active cues change. `getActiveTextCues` reads them once, such as in an event handler. Pass it a store typed with your player’s features, such as the one the preset’s `usePlayer` returns:

```tsx
import { getActiveTextCues } from '@videojs/react';
import { usePlayer } from '@videojs/react/video';

function AnswerButton() {
  const store = usePlayer();
  const answer = () => {
    const [cue] = getActiveTextCues(store, quizTrack);
    console.log(cue?.value?.question);
  };

  return <button onClick={answer}>Answer</button>;
}
```

## API Reference

### With Definition

`getActiveTextCues<Cue extends MediaTextCue>(source, track): readonly Cue[]`

The cues active now on the tracks a track definition matches, typed by the definition. With a schema, cues whose value fails it are skipped.

`player.store.subscribe(() => { const [question] = getActiveTextCues(player.store, quizTrack); });`

#### Parameters

| Parameter | Type | Default | Description |
| --- | --- | --- | --- |
| `source` (required) | `{ textCues: readonly MediaTrackCues[] }` | — | State that carries text cues, such as the player store. |
| `track` (required) | `{ kind: 'subtitles' \| 'captions' \| 'descriptions' \| 'chapters' \| 'metadata'; label?: string; language?: string; schema?: StandardSchemaV1 }` | — | The track definition to read. |

#### Return Value

`readonly Cue[]`

### With Filter

`getActiveTextCues(source, filter?): readonly MediaTextCue[]`

The cues active now on the tracks a filter matches, from the media or the app.

#### Parameters

| Parameter | Type | Default | Description |
| --- | --- | --- | --- |
| `source` (required) | `{ textCues: readonly MediaTrackCues[] }` | — | State that carries text cues, such as the player store. |
| `filter` | `{ kind?: TextTrackKind \| readonly TextTrackKind[]; label?: string; language?: string } \| ((track: MediaTextTrack) => boolean)` | — | Picks tracks by kind, label, or language, or with a function. Defaults to every track being read. |

#### Return Value

`readonly MediaTextCue[]`

---

React documentation: https://videojs.org/docs/framework/react/llms.txt
All documentation: https://videojs.org/llms.txt
