docs(react): clarify usePlayer typed vs untyped store access#1663
Conversation
Add a note callout on the use-player reference page contrasting the typed Player.usePlayer (from createPlayer) with the untyped standalone usePlayer, and enrich the standalone hook's JSDoc so the generated reference explains the UnknownStore return and selector-based typing. Refs videojs#1483
👷 Deploy request for vjs10-site pending review.Visit the deploys page to approve it
|
|
@Jerricho93 is attempting to deploy a commit to the Mux Team on Vercel. A member of the Team first needs to authorize it. |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
decepulis
left a comment
There was a problem hiding this comment.
Close. One blocking comment (we don't want to tell folks about @videojs/core) and two suggestions to tighten up the copy a bit
|
|
||
| usePlayer(); // UnknownStore (state: unknown) | ||
| usePlayer(selectPlayback); // PlaybackState | undefined | ||
| ``` |
There was a problem hiding this comment.
- blocking: we try not to expose @videojs/core. Luckily, @videojs/react re-exports the important bits.
- suggestion: I wonder if we need the aside. The code block feels visually-prominent enough.
- suggestion: The aside feels redundant with some of what comes above it. Maybe we can combine the two... something like this?
What do you think of a change like this?
`Player.usePlayer` (from <DocsLink slug="reference/create-player">`createPlayer`</DocsLink>) gives you access to the player store from any component within a `Player.Provider`. It's typed to the features you passed to `createPlayer`. It has two overloads — without arguments for direct store access, or with a selector for reactive state subscriptions.
`usePlayer` also available as a standalone import (`import { usePlayer } from '@videojs/react'`), but the standalone version returns an `UnknownStore`. Pass a premade selector to recover typing:
```tsx
import { usePlayer, selectPlayback } from '@videojs/react';
usePlayer(); // UnknownStore (state: unknown)
usePlayer(selectPlayback); // PlaybackState | undefined
```
There was a problem hiding this comment.
This looks great! I'll push the changes right now. Will change the blocking one, and apply both suggestions, since they help understand cleanly what we want to inform the users
Address PR review: drop the redundant aside in favor of a two-paragraph intro plus example, and import selectPlayback from @videojs/react rather than @videojs/core/dom (which isn't part of the public API surface). Refs videojs#1483
decepulis
left a comment
There was a problem hiding this comment.
Excellent. Thank you!
Closes #1483
Summary
The
use-playerreference page mentioned the typed-vs-untyped distinction only in a single easy-to-miss sentence, so users assumed the standaloneusePlayer()is supposed to returnunknown. This makes the distinction prominent on the page and corrects the standalone hook's generated reference.Changes
use-playerreference page:Player.usePlayer(fromcreatePlayer) is typed to the configured features and needs no selector, while the standaloneimport { usePlayer }returns an untypedUnknownStoreand needs a premade selector to recover typing.usePlayerJSDoc so the generated reference explains theUnknownStorereturn — and that inline selectors stayunknownwhile premade selectors (e.g.selectPlayback) carry their type.Testing
pnpm -F site api-docs— regenerates the util reference; confirmeduse-player.jsonnow includes the new JSDoc paragraphs.pnpm build:site— site builds and the page renders.Note
Low Risk
Documentation and JSDoc only; no runtime or type behavior changes.
Overview
Improves discoverability of typed vs. untyped
usePlayerbehavior so users don’t treat standaloneunknownreturns as a bug.The
use-playerreference adds a note callout and a short example:Player.usePlayerfromcreatePlayer()is feature-typed without a selector; standaloneimport { usePlayer } from '@videojs/react'yields anUnknownStore, with typing recoverable via premade selectors likeselectPlayback.JSDoc on the standalone
usePlayeroverloads now states the same — no feature knowledge,UnknownStore/UnknownState, inline selectors stayunknown, premade selectors carry their return type — so generated API reference matches the docs page.Reviewed by Cursor Bugbot for commit 8c447e2. Bugbot is set up for automated code reviews on this repo. Configure here.