hooks

Documents client-side React hooks for navigation, loaders, and state in @rangojs/router.

Updated Nov 7, 2025
One-click install
npx skills add https://github.com/rangojs/rango --skill hooks-rangojs
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: hooks
Source: https://github.com/rangojs/rango/tree/main/packages/rangojs-router/skills/hooks
Command: npx skills add https://github.com/rangojs/rango --skill hooks-rangojs

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires @rangojs/router, and includes references (resource) components.

What problem does it solve? Client components in a Rango application need access to the current URL, route params, search params, navigation state, loader data, and history state, and choosing the wrong hook or entrypoint leads to broken reads, unnecessary re-renders, or server round-trips. ## Core Features & Use Cases - URL and navigation hooks: useParams, usePathname, useSearchParams, useNavigation, useRouter, useSegments, and useLinkStatus expose the current location and stable router actions like push, replace, refresh, and prefetch. - Loader data hooks: useLoader and useFetchLoader consume server loader data with streaming, Suspense integration, keyed refetch scoping, and cross-loader refresh groups via useRefreshLoaders. - State and outlet APIs: useLocationState reads typed persistent or flash history state, useHandle accumulates route handle data, useAction tracks server action invocations, and Outlet/useOutlet render child content in layouts. - Use Case: A client component on a product page needs the productId param, the loader's price data, and a pending spinner during navigation — the decision table maps each need to the exact hook and its companion reference file. ## Quick Start Ask the assistant which Rango client hook to use for reading a route param or loader data in a client component and show a typed example.

Frequently Asked Questions about hooks

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I read route params in a Rango client component?

Use useParams() from @rangojs/router/client to get merged params from all matched route segments as a readonly map. You can annotate the shape with a generic like useParams<{ productId: string }>() or pass a selector to re-render only when one value changes.

How do I access loader data in a React client component?

Use useLoader(LoaderDef) for loaders registered on the route; it suspends until streamed data lands and returns guaranteed data. Use useFetchLoader for on-demand fetching with load(), which supports params, JSON or FormData bodies, and keyed refetch scoping.

What is the difference between useLoader and useFetchLoader?

useLoader is strict: data is guaranteed once the read returns and the first read suspends until the loader streams in. useFetchLoader is flexible: data may be undefined until you call load() on demand, and unregistered loaders keep per-component results.

Can I update search params without a server round-trip?

Yes. Pass { revalidate: false } to setSearchParams, router.push, router.replace, or a Link to update the URL and re-render hooks without an RSC server fetch. It only applies when the pathname stays the same; pathname changes always trigger a full navigation.

Why does useLoader suspend instead of showing isLoading on first read?

Loaders stream with the RSC payload, so a first read whose data has not arrived suspends to the nearest Suspense boundary or the route's loading() fallback. The isLoading flag only covers later refetches via load(), key refreshes, or group refreshes.

When should I not use these client hooks for data fetching?

Do not use client hooks to fetch data; data fetching belongs in server-side loaders created with createLoader. Client hooks like useLoader only consume what a loader resolved, and controlling when a loader re-runs after an action is done with revalidate() in the server DSL.