mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-04 22:16:40 +00:00
Use callback optimizations
This commit is contained in:
1 parent
68360e7619
commit
9e648d858b
1 file changed
+5
-5
@@ -1,4 +1,4 @@
|
|||||||
import { useState, useEffect, useRef } from 'react';
|
import { useState, useEffect, useRef, useCallback } from 'react';
|
||||||
import { Howl } from 'howler';
|
import { Howl } from 'howler';
|
||||||
|
|
||||||
interface ISoundOptions {
|
interface ISoundOptions {
|
||||||
@@ -48,7 +48,7 @@ const useSound = (
|
|||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, [volume]);
|
}, [volume]);
|
||||||
|
|
||||||
const play = () => {
|
const play = useCallback(() => {
|
||||||
if (!sound) return;
|
if (!sound) return;
|
||||||
|
|
||||||
if (interrupt) return sound.stop();
|
if (interrupt) return sound.stop();
|
||||||
@@ -66,9 +66,9 @@ const useSound = (
|
|||||||
if (isMounted.current) {
|
if (isMounted.current) {
|
||||||
setPlaying(true);
|
setPlaying(true);
|
||||||
}
|
}
|
||||||
};
|
}, [interrupt, sound]);
|
||||||
|
|
||||||
const stop = () => {
|
const stop = useCallback(() => {
|
||||||
if (!sound) return;
|
if (!sound) return;
|
||||||
|
|
||||||
sound.stop();
|
sound.stop();
|
||||||
@@ -76,7 +76,7 @@ const useSound = (
|
|||||||
if (isMounted.current) {
|
if (isMounted.current) {
|
||||||
setPlaying(false);
|
setPlaying(false);
|
||||||
}
|
}
|
||||||
};
|
}, [sound]);
|
||||||
|
|
||||||
return { play, playing, stop };
|
return { play, playing, stop };
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in new issue
Block a user