useSelector is the low-level primitive that powers useStore and useSnapshot. It accepts explicit subscribe and getSnapshot functions, a selector to derive state, and an optional isEqual comparator. Most applications should use useStore or Player.usePlayer instead.
Exported from @videojs/store/react and re-exported from @videojs/react.
Parameters
A function that registers a callback to be invoked when the external store changes, and returns an unsubscribe function. Passed directly to React’s
useSyncExternalStore.A function that returns the current snapshot value from the external store. Must return a stable reference when the store has not changed.
Derives the value to return from the current snapshot. The hook re-renders the component only when the derived value changes (controlled by
isEqual).Equality function used to determine if the derived value has changed. Defaults to
shallowEqual, which compares object properties one level deep. Pass Object.is for reference equality, or a custom comparator for deeply nested structures.Return value
ReturnsR — the value derived by the selector from the latest snapshot.
Usage
Time display with custom subscription
Custom equality comparison
Relationship to other hooks
| Hook | Input | When to use |
|---|---|---|
useStore(store, selector?) | Store instance | Player and store access with optional selector |
useSnapshot(state, selector?) | State container | Subscribe to raw State changes |
useSelector(subscribe, getSnapshot, selector, isEqual?) | Custom subscribe/snapshot | Full control over subscription, non-standard sources |
useStore when working with a store instance, and useSnapshot when working with a State container. Reach for useSelector only when you need to integrate with a custom external source or require precise control over equality comparison.
Equality comparison
The defaultshallowEqual compares the top-level properties of objects using Object.is, which is sufficient for most selector return values. For primitive returns (strings, numbers, booleans), equality is always reference equality.