refactor: use nullish operator

This commit is contained in:
MAZE 2024-06-14 18:57:13 +04:30
parent ffe260f4a0
commit 9d633a9637
2 changed files with 3 additions and 4 deletions

View file

@ -20,7 +20,7 @@ export function useSoundEffect(src: string, volume: number = 1) {
}, [src, isBrowser]); }, [src, isBrowser]);
useEffect(() => { useEffect(() => {
if (sound) sound.volume(typeof volume === 'number' ? volume : 1); if (sound) sound.volume(volume ?? 1);
}, [sound, volume]); }, [sound, volume]);
const play = useCallback(() => { const play = useCallback(() => {

View file

@ -34,13 +34,12 @@ export function useSound(
useEffect(() => { useEffect(() => {
if (sound) { if (sound) {
sound.loop(typeof options.loop === 'boolean' ? options.loop : false); sound.loop(options.loop ?? false);
} }
}, [sound, options.loop]); }, [sound, options.loop]);
useEffect(() => { useEffect(() => {
if (sound) if (sound) sound.volume(options.volume ?? 0.5);
sound.volume(typeof options.volume === 'number' ? options.volume : 0.5);
}, [sound, options.volume]); }, [sound, options.volume]);
const play = useCallback(() => { const play = useCallback(() => {