add-hook

Create React data-fetching hooks using FunctionSpaceContext and useCacheSubscription.

Updated Aug 23, 2026
One-click install
npx skills add https://github.com/functionspace/fs_trading_sdk --skill add-hook-functionspace
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: add-hook
Source: https://github.com/functionspace/fs_trading_sdk/tree/main/.claude/skills/add-hook
Command: npx skills add https://github.com/functionspace/fs_trading_sdk --skill add-hook-functionspace

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill provides a structured approach to creating a new data-fetching hook for the @functionspace/react package that adheres to the SDK's conventions, reducing boilerplate and ensuring correct context usage and cache integration.

Core Features & Use Cases

  • Context-aware: uses the FunctionSpaceContext to access the API client and workspace state.
  • Cache-backed: builds a stable CacheKey with useMemo and subscribes via useCacheSubscription to keep data in sync.
  • Deterministic requests: wraps the core function in useCallback with an AbortSignal for cancellation and clean error handling.
  • Extensible pattern: provides a clear blueprint for adding new hooks across the React layer for market data queries.

Quick Start

Create a new React hook file in packages/react/src following the canonical pattern and export it from the React package index.

Frequently Asked Questions about add-hook

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

FAQPage Schema
How do I create a reusable React data-fetching hook with context and cache integration?

Create a reusable React data-fetching hook by using useContext for the FunctionSpaceContext, useMemo for stable cache keys, useCallback for the core function with AbortSignal, and useCacheSubscription to sync data with the cache.

What is the best way to structure a React hook for SDK market data queries?

The best way to structure a React hook for market data queries is to follow a canonical pattern that wraps requests in useCallback for deterministic fetching and uses useCacheSubscription to keep the queried data synchronized with the cache.

How does useCacheSubscription work with a React data-fetching hook?

useCacheSubscription works by subscribing the React data-fetching hook to the query cache, ensuring the component re-renders with fresh data automatically whenever the cached market data updates.

Can I use useCallback and AbortSignal for request cancellation in a React hook?

Yes, you can wrap the core data-fetching function in useCallback and pass an AbortSignal to enable request cancellation, which ensures clean error handling and prevents state updates on unmounted components.

Does this React hook pattern require a specific workspace state to fetch data?

Yes, the hook relies on FunctionSpaceContext to access the API client and workspace state, meaning the React component must be wrapped in the appropriate context provider before it can successfully fetch market data.

What are the limitations of building React hooks with useMemo for cache keys?

The limitation of using useMemo for cache keys is that the key generation depends on stable dependency arrays; if the hook's input parameters are not referentially stable, the memoized key can change unnecessarily and trigger redundant cache subscriptions.