Files
med-notes/.pnpm-store/v10/files/cd/72879a3dbf79961addf5bd9050489d69e9159aa342429894fbd4379e77602cc72afecb6b67e8e30442c25ae784741e9581722de083944b69ccc8d8861b4daf
2025-05-09 05:30:08 +02:00

48 lines
1.5 KiB
Plaintext

"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const React = require("react");
const invariant = require("tiny-invariant");
const useRouterState = require("./useRouterState.cjs");
const matchContext = require("./matchContext.cjs");
function _interopNamespaceDefault(e) {
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
if (e) {
for (const k in e) {
if (k !== "default") {
const d = Object.getOwnPropertyDescriptor(e, k);
Object.defineProperty(n, k, d.get ? d : {
enumerable: true,
get: () => e[k]
});
}
}
}
n.default = e;
return Object.freeze(n);
}
const React__namespace = /* @__PURE__ */ _interopNamespaceDefault(React);
function useMatch(opts) {
const nearestMatchId = React__namespace.useContext(
opts.from ? matchContext.dummyMatchContext : matchContext.matchContext
);
const matchSelection = useRouterState.useRouterState({
select: (state) => {
const match = state.matches.find(
(d) => opts.from ? opts.from === d.routeId : d.id === nearestMatchId
);
invariant(
!((opts.shouldThrow ?? true) && !match),
`Could not find ${opts.from ? `an active match from "${opts.from}"` : "a nearest match!"}`
);
if (match === void 0) {
return void 0;
}
return opts.select ? opts.select(match) : match;
},
structuralSharing: opts.structuralSharing
});
return matchSelection;
}
exports.useMatch = useMatch;
//# sourceMappingURL=useMatch.cjs.map