UNPKG

media-stream-player

Version:

Player built on top of media-stream-library

21 lines (17 loc) 448 B
import { useState, useCallback } from 'react' export const useSwitch = ( initialValue = false, ): readonly [boolean, (state?: boolean) => void] => { const [value, setValue] = useState(initialValue) const toggleValue = useCallback( (state?: boolean) => { if (state !== undefined) { setValue(state) } else { setValue((oldValue) => !oldValue) } }, [setValue], ) return [value, toggleValue] }