From 9e648d858b5d649e019f52b42583d0936140edff Mon Sep 17 00:00:00 2001 From: Taso Date: Sun, 14 Feb 2021 23:20:39 -0500 Subject: [PATCH] Use callback optimizations --- phone/src/os/phone/hooks/useSound.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/phone/src/os/phone/hooks/useSound.ts b/phone/src/os/phone/hooks/useSound.ts index b0b285b..27efa1c 100644 --- a/phone/src/os/phone/hooks/useSound.ts +++ b/phone/src/os/phone/hooks/useSound.ts @@ -1,4 +1,4 @@ -import { useState, useEffect, useRef } from 'react'; +import { useState, useEffect, useRef, useCallback } from 'react'; import { Howl } from 'howler'; interface ISoundOptions { @@ -48,7 +48,7 @@ const useSound = ( // eslint-disable-next-line react-hooks/exhaustive-deps }, [volume]); - const play = () => { + const play = useCallback(() => { if (!sound) return; if (interrupt) return sound.stop(); @@ -66,9 +66,9 @@ const useSound = ( if (isMounted.current) { setPlaying(true); } - }; + }, [interrupt, sound]); - const stop = () => { + const stop = useCallback(() => { if (!sound) return; sound.stop(); @@ -76,7 +76,7 @@ const useSound = ( if (isMounted.current) { setPlaying(false); } - }; + }, [sound]); return { play, playing, stop }; };