usePlayer gives you access to the player store from any component inside a Player.Provider. It has two overloads — call it without arguments to get the store for imperative actions, or pass a selector function to subscribe to reactive state.
The version returned by createPlayer is typed to the features you provided. The standalone import from @videojs/react returns an untyped store.
Overloads
Without selector — store access
Returns the store instance directly. The component does not subscribe to state changes and will not re-render when state updates. Use this overload for imperative actions likeplay, pause, and setVolume.
Call with no arguments to get the store instance without subscribing to state.
Store — the full, typed store object.
With selector — reactive subscription
Pass a selector function to derive and subscribe to a value from store state. The component re-renders when the derived value changes, using shallow equality by default.A function that receives the current store state and returns the value to subscribe to. The component re-renders when the returned value changes (shallow equality).
R — the value returned by the selector.
Using feature selectors
Use pre-built selectors from@videojs/react to select common feature slices:
Standalone import
The standaloneusePlayer exported from @videojs/react behaves identically but returns an untyped store. Use Player.usePlayer (from createPlayer) to get typed state.
Rules
- Must be called inside a
Player.Provider. - Throws if called outside a provider context.
- The no-argument overload does not cause re-renders on state changes.
- The selector overload uses shallow equality by default. Return a stable primitive or flat object to avoid unnecessary re-renders.