Server: Phase 2 (REVIEW not respected yet)

This commit is contained in:
Thomas Karner committed 2026-09-21 11:24:43 +02:00
1 parent 5d16ded553
commit 142b47674d
4271 files changed
+1203269

No files matched your search

+29
View File
@@ -0,0 +1,29 @@
"use client";
import { useRouter } from "./useRouter.js";
import { useStructuralSharing } from "./useMatch.js";
import { isServer } from "@tanstack/router-core/isServer";
import { useSelector } from "@tanstack/react-store";
//#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;
}
return useSelector(router.stores.location, useStructuralSharing(opts, router));
}
//#endregion
export { useLocation };
//# sourceMappingURL=useLocation.js.map