useSnapshot subscribes to a State container and returns its current value,
re-rendering the component when the value changes. It is built on
useSelector and uses shallowEqual by default.
Import
Overloads
Without selector
Returns the full state object. Re-renders on every state change.With selector
Returns a derived value. Re-renders only when the derived value changes according toisEqual (defaults to shallowEqual).
Parameters
The
State container to subscribe to. State is a reactive primitive that
holds an object value and notifies subscribers on change.Optional. Derives a value from the current state. When provided, the component
only re-renders when the returned value changes.
Optional. Custom equality comparator used to decide whether the derived value
has changed. Defaults to
shallowEqual.Return value
When called without a selector, the full current state object
T. When called
with a selector, the derived value R.Usage
Full state subscription
CountDisplay.tsx
Derived value with selector
Use a selector to subscribe to only the part of state you need. The component will not re-render when unrelated parts of the state change.Count.tsx
Custom equality comparator
Pass a customisEqual function when selector returns a derived object and you
need control over when re-renders occur.
TimeDisplay.tsx
State containers vs. stores
AState container is the low-level reactive primitive in @videojs/store. Stores are built on top of State containers and add features, actions, and lifecycle management.
| Hook | Input | Subscribes to |
|---|---|---|
useSnapshot | State<T> | Raw state container |
useStore | Store instance | Store-backed state with features |
useSnapshot when working with standalone State containers outside the
player store system — for example, custom state in component libraries. For
player state, use usePlayer or
useStore.
HTML equivalent
The HTML equivalent isSnapshotController,
which provides the same subscription behavior for DOM-based environments.