one
Version:
One is a React framework for web, iOS, and Android apps.
28 lines (25 loc) • 829 B
JavaScript
import { useRef } from "react";
import { useRouter } from "../hooks.native.js";
import { useFocusEffect } from "../useFocusEffect.native.js";
var redirectsInFlight = /* @__PURE__ */ new Set();
function Redirect(param) {
var { href } = param;
var router = useRouter();
var hasRedirected = useRef(false);
useFocusEffect(function() {
if (hasRedirected.current) return;
var 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(function(error) {
hasRedirected.current = false;
console.error(error);
}).finally(function() {
redirectsInFlight.delete(key);
});
}, [href]);
return null;
}
export { Redirect };
//# sourceMappingURL=Redirect.native.js.map