- Home
- Skills
- Frontend & Web Apps
- React Custom Hooks with TypeScript
More screenshots
Works with the AI Agents you already use
React Custom Hooks with TypeScript
Design custom React hooks that stay small, honest, and testable: one job per hook, deliberate return shapes, stale-closure discipline, race-safe async, and tests that cover the contract.
$5
React Custom Hooks with TypeScript
Example session with this skill installed
Three components in our dashboard each hand-roll their own fetch-with-spinner logic, and double-clicking Refresh sometimes lands stale data. Design one hook to replace all of it.
- Read your context and instructions
- Compiled the react custom hooks
HOOK DESIGN — produced by applying the skill to the request.
Job statement (one sentence, written first): "Run a caller-supplied async action and report its lifecycle, with only the latest run allowed to land." The three components' shared concern is exactly this; their differing parts (what to fetch, how to render) stay in the components.
Return shape, per the decision table: a discriminated status union — { status: "idle" | "pending" } | { status: "ok"; value } | { status: "failed"; error } plus run and reset. Not booleans: isLoading && !isError && !data admits states that cannot happen and misses the stale one that can.
The stale-data bug, diagnosed: each component sets state whenever its promise resolves, so a slow first request resolving after a fast second one overwrites fresh data. Fix built into the design: a generation counter. Each run() increments it and captures its generation; a resolution only sets state if its generation is still current. The double-click case is then structural, not lucky — the first run's result is discarded by construction. reset() increments the counter too, so it doubles as cancellation, and it beats an isMounted flag because unmount is only one way a response goes stale; a newer run is the other.
Contract tests specified with the design: idle → pending → ok on a single run; error lands as failed with the thrown value normalized to Error; two rapid runs resolve out of order and only the second result is displayed; reset during flight leaves the hook idle after the promise settles. Lint gate: rules-of-hooks as error, exhaustive-deps as warn, no disable without a written reason.
Connects securely to your tools. The creator never sees your data.
About this skill
Custom hooks fail in predictable ways: one hook quietly managing three unrelated concerns, a return value shaped as boolean soup where impossible states are representable, an effect orchestrating state instead of synchronizing with something external, and the classic stale-closure or double-click race discovered in production. This skill is the design discipline that prevents them. It opens with the non-negotiable rules (top-level calls, use naming, lint enforcement) and an inputs/outputs contract: the deliverable is a hook whose one-sentence job is written before the code, a return-shape contract, and tests for the transitions. The protocol walks the decisions in order — state the one job (an "and" joining unrelated concerns means split), choose the return shape from a decision table (tuple, object, or discriminated status union), separate derivation from synchronization, pass the stale-closure checklist (callback refs, cleanup, generation counters over isMounted flags), and test the contract including a race or unmount case. Two complete worked examples anchor it: a race-safe useAsyncAction built on a generation counter and a discriminated union, and a subscription wrapper showing when useSyncExternalStore beats a hand-rolled listener. Composition patterns cover building hooks from smaller hooks, the sanctioned latest-ref pattern, extracting only on the second use, and data-fetching honesty when a library already exists. A hook spec template, a six-dimension design review rubric, a review smell list, and a "when not to write a hook" section round it out — some logic is a plain function, and saying so is part of the deliverable.
Find more skills like this on the Claude Skills Marketplace, the Codex Skills Marketplace and the Gemini Skills Marketplace, or browse Claude Skills for Frontend & Web Apps.
- It teaches design judgment, not a recipe library — you get two complete worked examples and the patterns to build others, not a catalog of fifty hooks.
- Hooks do not run in React Server Components; server-side data loading is explicitly out of scope, and the skill routes that work elsewhere.
- Framework-specific data layers (router loaders, server actions) are covered only at the boundary — where a hook should wrap a library rather than compete with it.
How to use
- 1
Connect your agent to the Agensi MCP
Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup
- 2
Sign in to Agensi
Your agent shows a sign-in link. Sign in and click Allow.
- 3
Ask for what you need
Your agent loads this skill and uses it on your task. It always asks before buying a skill.
Reviews
No reviews yet
Be one of the first to try it. Every listed skill goes through the trust checks below.
Security scanned
Checked by our 8-point scan before listing
Fresh listing
Recently published to Agensi
Money-back guarantee
Doesn't do what its page promises? You get your money back.
Trust & safety
Security scan
Security scan passed 24 days ago
Permissions
No special permissions declared or detected