mirror of
https://github.com/zoriya/react-native-omni.git
synced 2026-08-05 05:36:17 +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;
|
||||
}, [value, config]);
|
||||
|
||||
// prev/next are triggered by the app (or the media session) rather than the
|
||||
// media element
|
||||
useEffect(() => {
|
||||
// don't use callbackRef.current directly to keep future callback updates
|
||||
const cb = () => (callbackRef.current as () => void)();
|
||||
if (event === "prev") {
|
||||
const cb = callbackRef.current as () => void;
|
||||
player.onPrev.add(cb);
|
||||
return () => {
|
||||
player.onPrev.delete(cb);
|
||||
};
|
||||
}
|
||||
if (event === "next") {
|
||||
const cb = callbackRef.current as () => void;
|
||||
player.onNext.add(cb);
|
||||
return () => {
|
||||
player.onNext.delete(cb);
|
||||
|
||||
Reference in New Issue
Block a user