Files
SnowLuma/.pnpm-store/v11/files/b5/b67536737d592fb118c1e530878a3702677ba6046841af5dcb0c3ad8fe4c786c2c603073c6d6f700b9dd6cb394d521a0c88a94e12f3016dca7a970109b0c4c
T
TanTan 2a69b23b47
Dev Build / cleanup (push) Canceled after 0s
Dev Build / typecheck (push) Canceled after 0s
Dev Build / build (linux-arm64, ubuntu-24.04-arm, linux-arm64) (push) Canceled after 0s
Dev Build / build (linux-x64, ubuntu-latest, linux-x64) (push) Canceled after 0s
Dev Build / build (win-x64, windows-latest, win32-x64) (push) Canceled after 0s
Dev Build / dispatch-dev-docker (push) Canceled after 0s
docs: 仓库链接指向本镜像仓库
2026-11-13 09:27:07 +08:00

39 lines
1.4 KiB
Plaintext

"use client";
import { useRouter } from "./useRouter.js";
import { replaceEqualDeep } from "@tanstack/router-core";
import { useRef } from "react";
import { useStore } from "@tanstack/react-store";
import { isServer } from "@tanstack/router-core/isServer";
//#region src/useLocation.tsx
/**
* Read the current location from the router state with optional selection.
* Useful for subscribing to just the pieces of location you care about.
*
* Options:
* - `select`: Project the `location` object to a derived value
* - `structuralSharing`: Enable structural sharing for stable references
*
* @returns The current location (or selected value).
* @link https://tanstack.com/router/latest/docs/framework/react/api/router/useLocationHook
*/
function useLocation(opts) {
const router = useRouter();
if (isServer ?? router.isServer) {
const location = router.stores.location.get();
return opts?.select ? opts.select(location) : location;
}
const previousResult = useRef(void 0);
return useStore(router.stores.location, (location) => {
const selected = opts?.select ? opts.select(location) : location;
if (opts?.structuralSharing ?? router.options.defaultStructuralSharing) {
const shared = replaceEqualDeep(previousResult.current, selected);
previousResult.current = shared;
return shared;
}
return selected;
});
}
//#endregion
export { useLocation };
//# sourceMappingURL=useLocation.js.map