mirror of
https://github.com/chillpadclub/bedolaga-cabinet.git
synced 2026-07-30 02:23:47 +00:00
fix: prevent useCloseOnSuccessNotification from firing on mount
The hook checked closeOthersSignal > 0 which only skipped signal=0. After first payment, signal stays at 1+ forever causing TopUpAmount to immediately navigate away on every mount. Now tracks the signal value at mount time and only reacts to changes after mount.
This commit is contained in:
@@ -67,9 +67,11 @@ export function useCloseOnSuccessNotification(onClose: () => void) {
|
|||||||
const onCloseRef = useRef(onClose);
|
const onCloseRef = useRef(onClose);
|
||||||
onCloseRef.current = onClose;
|
onCloseRef.current = onClose;
|
||||||
|
|
||||||
|
// Remember the signal value at mount time so we only react to NEW signals
|
||||||
|
const mountedSignalRef = useRef(closeOthersSignal);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// Skip the initial render (signal = 0)
|
if (closeOthersSignal !== mountedSignalRef.current) {
|
||||||
if (closeOthersSignal > 0) {
|
|
||||||
onCloseRef.current();
|
onCloseRef.current();
|
||||||
}
|
}
|
||||||
}, [closeOthersSignal]);
|
}, [closeOthersSignal]);
|
||||||
|
|||||||
Reference in New Issue
Block a user