UNPKG

one

Version:

One is a new React Framework that makes Vite serve both native and web.

33 lines (32 loc) 1.48 kB
import { useStateForPath } from "@react-navigation/core"; import { createContext, useRef } from "react"; import { getRouteInfo } from "./getRouteInfo"; import { jsx } from "react/jsx-runtime"; const RouteInfoContext = createContext(void 0); function RouteInfoContextProvider({ children }) { const currentState = useStateForPath(), currentStateRef = useRef(void 0), lastStateRef = useRef(void 0), cachedRouteInfoValueRef = useRef(void 0), lazilyCalculatedRouteInfo = useRef(void 0); return currentState && currentStateRef.current !== currentState && (lazilyCalculatedRouteInfo.current = makeLazilyCalculatedRouteInfo({ currentStateRef, lastStateRef, cachedRouteInfoValueRef })), currentStateRef.current = currentState, /* @__PURE__ */ jsx(RouteInfoContext.Provider, { value: currentState ? lazilyCalculatedRouteInfo.current : void 0, children }); } function makeLazilyCalculatedRouteInfo({ currentStateRef, lastStateRef, cachedRouteInfoValueRef }) { return new Proxy({}, { get(_, p) { const state = currentStateRef.current; if (!state) throw new Error("[lazilyCalculatedRouteInfo] cannot get state"); return (!cachedRouteInfoValueRef.current || lastStateRef.current !== state) && (cachedRouteInfoValueRef.current = getRouteInfo(state), lastStateRef.current = state), cachedRouteInfoValueRef.current[p]; } }); } export { RouteInfoContext, RouteInfoContextProvider }; //# sourceMappingURL=RouteInfoContext.js.map