Files
med-notes/.pnpm-store/v10/files/e2/5508011da19aa082a907b3bd3a6a2ddebef2190b27df3b0b10f97cab39e96ab2a4b0687732c0a9a0bc0cf575fcf9e594c94832028616633282a74a5a6b0c6e
2025-05-09 05:30:08 +02:00

31 lines
947 B
Plaintext

import * as React from "react";
import invariant from "tiny-invariant";
import { useRouterState } from "./useRouterState.js";
import { dummyMatchContext, matchContext } from "./matchContext.js";
function useMatch(opts) {
const nearestMatchId = React.useContext(
opts.from ? dummyMatchContext : matchContext
);
const matchSelection = 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;
}
export {
useMatch
};
//# sourceMappingURL=useMatch.js.map