one
Version:
One is a new React Framework that makes Vite serve both native and web.
28 lines (27 loc) • 866 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