More screenshots

    Works with the AI Agents you already use

    Claude CodeClaude CodeCursorCursorCodex CLICodex CLIDeepSeekDeepSeekMuseMuse+22 more

    React Custom Hooks with TypeScript

    1

    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

    Secure checkout via Stripe

    Money-back guarantee

    Converts to your local currency at checkout

    Security scanned
    React Custom Hooks with TypeScript

    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. 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. 2

      Sign in to Agensi

      Your agent shows a sign-in link. Sign in and click Allow.

    3. 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

    Listed24 days ago
    Updated21 days ago

    What's inside

    Frequently Asked Questions

    Both — the review half is arguably the more valuable one. The smell list (effects over ~10 lines or 3 dependencies, derivable state stored as state, 5+ returned fields, unexplained exhaustive-deps disables) plus the six-dimension rubric give you a repeatable pass over existing hooks, and the stale-closure checklist targets the bug class that survives normal code review.

    Because unmount is only one way a response goes stale. The reported bug — double-click Refresh, slow first response landing after the fast second — happens while the component is happily mounted, and `isMounted` does nothing for it. A generation counter makes "only the latest run lands" structural. AbortController is a fine complement for canceling the network work itself; the counter is what protects the state.

    No, and the skill says where the line is. Pure computation is a plain function; one-off logic stays in its component; extraction usually waits for the second call site, because the second consumer is what reveals the hook's real inputs. A hook with one fictional consumer collects timing and lifecycle bugs in exchange for indirection nobody needed.

    New in Frontend & Web Apps