FrameworkStyle

useStore

Hook to access store state and actions with optional selector-based subscriptions

useStore subscribes to a store instance directly. It has the same two overloads as usePlayer — without a selector for store access, or with a selector for reactive state. Within a player provider, usePlayer is usually simpler since it reads the store from context. Reach for useStore when you have a store instance directly or need to derive computed values from the store.

Examples

Store Access

Call useStore(store) without a selector to get the store instance back for imperative actions. The component does not subscribe to state changes.

import { createPlayer, usePlayer, useStore } from '@videojs/react';
import { Video, videoFeatures } from '@videojs/react/video';

import './StoreAccess.css';

const { Provider, Container } = createPlayer({
  features: videoFeatures,
});

function SeekControls() {
  const store = usePlayer();
  const s = useStore(store);

  return (
    <div className="react-use-store-access__controls">
      <button type="button" onClick={() => s.seek(0)}>
        Go to start
      </button>
      <button type="button" onClick={() => s.seek(s.state.duration / 2)}>
        Go to middle
      </button>
    </div>
  );
}

export default function StoreAccess() {
  return (
    <Provider>
      <Container className="react-use-store-access">
        <Video
          src="https://stream.mux.com/lhnU49l1VGi3zrTAZhDm9LUUxSjpaPW9BL4jY25Kwo4/highest.mp4"
          autoPlay
          muted
          playsInline
          loop
        />
        <SeekControls />
      </Container>
    </Provider>
  );
}

Selector Subscription

Pass a selector to derive and subscribe to computed values from the store. The component re-renders when the derived value changes, using shallow equality by default.

Remaining
0.0s
Progress
0.0%
import { createPlayer, usePlayer, useStore } from '@videojs/react';
import { Video, videoFeatures } from '@videojs/react/video';

import './Selector.css';

const { Provider, Container } = createPlayer({
  features: videoFeatures,
});

function DerivedState() {
  const store = usePlayer();
  const derived = useStore(store, (s) => ({
    remaining: s.duration - s.currentTime,
    progress: s.duration > 0 ? (s.currentTime / s.duration) * 100 : 0,
  }));

  return (
    <dl className="react-use-store-selector__state">
      <div>
        <dt>Remaining</dt>
        <dd>{derived.remaining.toFixed(1)}s</dd>
      </div>
      <div>
        <dt>Progress</dt>
        <dd>{derived.progress.toFixed(1)}%</dd>
      </div>
    </dl>
  );
}

export default function Selector() {
  return (
    <Provider>
      <Container className="react-use-store-selector">
        <Video
          src="https://stream.mux.com/lhnU49l1VGi3zrTAZhDm9LUUxSjpaPW9BL4jY25Kwo4/highest.mp4"
          autoPlay
          muted
          playsInline
          loop
        />
        <DerivedState />
      </Container>
    </Provider>
  );
}

API Reference

Without Selector

Access store state and actions.

Without selector: Returns the store, does NOT subscribe to changes. With selector: Returns selected state, re-renders when selected state changes (shallowEqual).

Parameters

Parameter Type Default
store* S

Return Value

S

With Selector

Select a value from the store. Re-renders when the selected value changes (shallowEqual).

Parameters

Parameter Type Default
store* S
selector* Selector<InferStoreState<S>, R>
isEqual Comparator<R>

Return Value

R

Video.js is a free and open source HTML5 video player.
The term VIDEO.JS is a registered trademark of Brightcove Inc.
© 2010–2026 Video.js contributors  |  Sponsored by Mux

VideoJS