Beta —
@videojs/store is close to stable. Experimental adoption in real projects is welcome.@videojs/store provides reactive state management designed for use across different rendering environments. It uses a selector-based subscription model to minimize unnecessary re-renders and updates, and ships separate bindings for HTML/DOM and React environments.
Installation
Exports
| Entry point | Description |
|---|---|
. | Core — createSelector, shallowEqual, and types |
./html | HTML/DOM store bindings |
./react | React store bindings — useSelector, useStore |
How it works
The store uses a selector-based subscription model. Rather than subscribing to the entire state tree, you define selectors that derive specific values. Subscribers are only notified when the selected value changes, as determined by a comparator function (default:shallowEqual).
Core API
createSelector
Creates a memoized selector function. Use selectors to derive specific values from state:
shallowEqual
The default comparator used by selectors. Performs a shallow equality check on objects and arrays:
createSelector when you need stricter or looser equality:
React bindings (./react)
The React bindings integrate the store with React’s rendering model:
| Export | Description |
|---|---|
useSelector(selector) | Subscribes a component to a slice of store state; re-renders only when the selected value changes |
useStore() | Returns the raw store instance |
HTML bindings (./html)
The HTML bindings connect the store to DOM elements outside of a component framework:
Types
| Type | Description |
|---|---|
Selector<State, Value> | A function that derives a value from state |
Comparator<Value> | A function (a: Value, b: Value) => boolean used to detect changes |
Peer dependencies
| Package | Required | Notes |
|---|---|---|
@videojs/element | Optional | Required only when using ./html bindings |
react ^18 || ^19 | Optional | Required only when using ./react bindings |
Related packages
@videojs/core
Core player logic that builds on top of this package.
@videojs/react
React package that re-exports useSelector and useStore.
@videojs/utils
Shared utilities used by this package.
@videojs/html
HTML package that uses the HTML store bindings.