one
Version:
One is a React framework for web, iOS, and Android apps.
27 lines (24 loc) • 784 B
JavaScript
import { useRef } from "react";
import { useRouter } from "../hooks.mjs";
import { useFocusEffect } from "../useFocusEffect.mjs";
const redirectsInFlight = /* @__PURE__ */ new Set();
function Redirect({ href }) {
const router = useRouter();
const hasRedirected = useRef(false);
useFocusEffect(() => {
if (hasRedirected.current) return;
const key = typeof href === "string" ? href : JSON.stringify(href);
if (redirectsInFlight.has(key)) return;
hasRedirected.current = true;
redirectsInFlight.add(key);
Promise.resolve(router.replace(href)).catch((error) => {
hasRedirected.current = false;
console.error(error);
}).finally(() => {
redirectsInFlight.delete(key);
});
}, [href]);
return null;
}
export { Redirect };
//# sourceMappingURL=Redirect.mjs.map