[Video] Remember mute state while scrolling (#5331)

This commit is contained in:
Hailey 2024-09-13 14:07:13 -07:00 committed by GitHub
parent 791bc7afbe
commit 843f9925f5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 121 additions and 83 deletions

View file

@ -0,0 +1,32 @@
import React from 'react'
const Context = React.createContext(
{} as {
muted: boolean
setMuted: (muted: boolean) => void
},
)
export function Provider({children}: {children: React.ReactNode}) {
const [muted, setMuted] = React.useState(true)
const value = React.useMemo(
() => ({
muted,
setMuted,
}),
[muted, setMuted],
)
return <Context.Provider value={value}>{children}</Context.Provider>
}
export function useVideoVolumeState() {
const context = React.useContext(Context)
if (!context) {
throw new Error(
'useVideoVolumeState must be used within a VideoVolumeProvider',
)
}
return context
}