usePlaybackInfo
React Hook for retrieving playback details for a playback ID.
Hook for retrieving playback information related to a playback ID. Used
internally in the Player
to fetch the playback URL
for a playback ID.
Usage
The following examples assume a playback ID has been created for an asset or stream.
If a falsy playback ID is provided, the query will be skipped.
Return Value
The return value is partially based on Tanstack Query, with some return types aggregated for simplicity.
Configuration
playbackId
Playback identifier. Can also be a string passed as the only parameter.
UseQueryOptions
The usePlaybackInfo
hook also supports any
Tanstack Query
useQuery
options, such as refetchInterval
or enabled
. These override any
configs passed by default by the internal hook.
SSR
The following section only applies to web-based use-cases - React Native has no concept of SSR.
Next.js
The usePlaybackInfo
hook also comes with a
Tanstack Query prefetch query,
prefetchPlaybackInfo
, which makes it easy to prefetch data for server-side
rendering.
First, you add a
getStaticProps
function to the page which you want to prefetch data on. The props should match
the usePlaybackInfo
hook to ensure that the correct data is prefetched.
We need to update the _app.tsx
to pass the dehydratedState
in pageProps
to
the LivepeerConfig. We also move the livepeerClient
into a useMemo hook so
that a new client is created on each request.
That’s it! You now have data prefetching on the server, which is passed to the browser and used to hydrate the initial query client.
Other Frameworks
The process is very similar for other frameworks, with the exception that there
is a clearClient
boolean which should be used to ensure that the client cache
is not reused across users.
Was this page helpful?