mirror of
https://github.com/zoriya/react-native-omni.git
synced 2026-08-16 02:44:51 +00:00
fix(event): fix stale callbacks
This commit is contained in:
+2
-4
@@ -108,18 +108,16 @@ export const useEvent = <Event extends keyof OmniEvents>(
|
|||||||
prevRef.current = value;
|
prevRef.current = value;
|
||||||
}, [value, config]);
|
}, [value, config]);
|
||||||
|
|
||||||
// prev/next are triggered by the app (or the media session) rather than the
|
|
||||||
// media element
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
// don't use callbackRef.current directly to keep future callback updates
|
||||||
|
const cb = () => (callbackRef.current as () => void)();
|
||||||
if (event === "prev") {
|
if (event === "prev") {
|
||||||
const cb = callbackRef.current as () => void;
|
|
||||||
player.onPrev.add(cb);
|
player.onPrev.add(cb);
|
||||||
return () => {
|
return () => {
|
||||||
player.onPrev.delete(cb);
|
player.onPrev.delete(cb);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
if (event === "next") {
|
if (event === "next") {
|
||||||
const cb = callbackRef.current as () => void;
|
|
||||||
player.onNext.add(cb);
|
player.onNext.add(cb);
|
||||||
return () => {
|
return () => {
|
||||||
player.onNext.delete(cb);
|
player.onNext.delete(cb);
|
||||||
|
|||||||
Reference in New Issue
Block a user