this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

at e28f6d2f370b4e882ed6f23d08ca0f8d94dbac5f 47 lines 1.2 kB view raw
1import {createContext, useContext, useMemo, useState} from 'react' 2 3const Context = createContext<{ 4 muted: boolean 5 setMuted: React.Dispatch<React.SetStateAction<boolean>> 6 // web 7 volume: number 8 setVolume: React.Dispatch<React.SetStateAction<number>> 9} | null>(null) 10Context.displayName = 'VideoVolumeContext' 11 12export function Provider({children}: {children: React.ReactNode}) { 13 const [muted, setMuted] = useState(true) 14 const [volume, setVolume] = useState(1) 15 16 const value = useMemo( 17 () => ({ 18 muted, 19 setMuted, 20 volume, 21 setVolume, 22 }), 23 [muted, setMuted, volume, setVolume], 24 ) 25 26 return <Context.Provider value={value}>{children}</Context.Provider> 27} 28 29export function useVideoVolumeState() { 30 const context = useContext(Context) 31 if (!context) { 32 throw new Error( 33 'useVideoVolumeState must be used within a VideoVolumeProvider', 34 ) 35 } 36 return [context.volume, context.setVolume] as const 37} 38 39export function useVideoMuteState() { 40 const context = useContext(Context) 41 if (!context) { 42 throw new Error( 43 'useVideoMuteState must be used within a VideoVolumeProvider', 44 ) 45 } 46 return [context.muted, context.setMuted] as const 47}