Don't need useEffect for backgroundLocation

This commit is contained in:
Lim Chee Aun 2023-01-21 10:08:55 +08:00
parent d66d1bca12
commit 37fc65b47a

View file

@ -182,20 +182,18 @@ function App() {
} }
}, [isLoggedIn]); }, [isLoggedIn]);
const backgroundLocation = useRef(); const { prevLocation } = snapStates;
useEffect(() => { const backgroundLocation = useRef(prevLocation || null);
const { prevLocation } = snapStates; const isModalPage = /^\/s\//i.test(location.pathname);
const { pathname } = location; if (isModalPage) {
const { pathname: prevPathname } = prevLocation || {}; if (!backgroundLocation.current) backgroundLocation.current = prevLocation;
console.debug({ prevPathname, pathname }); } else {
const isModalPage = /^\/s\//i.test(pathname); backgroundLocation.current = null;
if (isModalPage) { }
if (!backgroundLocation.current) console.debug({
backgroundLocation.current = prevLocation; backgroundLocation: backgroundLocation.current,
} else { location,
backgroundLocation.current = null; });
}
}, [location]);
const nonRootLocation = useMemo(() => { const nonRootLocation = useMemo(() => {
const { pathname } = location; const { pathname } = location;