KS
Killer-Skills

ahooks — how to use ahooks how to use ahooks, ahooks vs react-query, ahooks install guide, what is ahooks, ahooks alternative to recoil, ahooks setup for react state management, ahooks react 18 compatibility, ahooks typescript support

v1.0.0
GitHub

About this Skill

Perfect for Frontend Agents utilizing React state management with hooks support and TypeScript ahooks is a React utility hooks library for state management, offering features like useSetState for grouped state updates and localStorage persistence.

Features

Provides useSetState for grouped state updates
Supports localStorage persistence for client-side data
Compatible with React 18+ and hooks support
Requires TypeScript v5+ for type inference
Optimized for client-side only applications
Does not cover data fetching or complex state machines

# Core Topics

blockmatic blockmatic
[0]
[0]
Updated: 3/6/2026

Quality Score

Top 5%
36
Excellent
Based on code quality & docs
Installation
SYS Universal Install (Auto-Detect)
Cursor IDE Windsurf IDE VS Code IDE
> npx killer-skills add blockmatic/basilic/ahooks

Agent Capability Analysis

The ahooks MCP Server by blockmatic is an open-source Categories.community integration for Claude and other AI agents, enabling seamless task automation and capability expansion. Optimized for how to use ahooks, ahooks vs react-query, ahooks install guide.

Ideal Agent Persona

Perfect for Frontend Agents utilizing React state management with hooks support and TypeScript

Core Value

Empowers agents to manage React state with grouped updates and localStorage persistence using ahooks v3+, enhancing their ability to handle complex state changes with features like useSetState, all while leveraging TypeScript v5+ for robust type inference and React 18+ for seamless hooks integration

Capabilities Granted for ahooks MCP Server

Implementing grouped state updates for efficient React component management
Persisting state changes in localStorage for a seamless user experience
Optimizing React application performance with targeted state updates

! Prerequisites & Limits

  • Requires React 18+ with hooks support
  • Limited to client-side applications due to browser API dependencies
  • Does not cover data fetching or complex state machines
Project
SKILL.md
4.4 KB
.cursorrules
1.2 KB
package.json
240 B
Ready
UTF-8

# Tags

[No tags]
SKILL.md
Readonly

Skill: ahooks

Scope

  • Applies to: ahooks v3+ utility hooks for React state management, grouped state updates, localStorage persistence
  • Does NOT cover: Data fetching (use TanStack Query), URL state management (use nuqs), complex state machines, async operations

Assumptions

  • ahooks v3+
  • React 18+ with hooks support
  • TypeScript v5+ (for type inference)
  • Client-side only (hooks require browser APIs for localStorage)

Principles

  • Use useSetState for grouped state that changes together (not URL-shareable)
  • Use useLocalStorageState for persistent state across browser sessions
  • Prefer nuqs for URL-shareable state over localStorage
  • Prefer TanStack Query for async operations and loading states
  • Use useState only for simple independent state (rare)

Constraints

MUST

  • Use useSetState for grouped state not in URL (form state, game engine state, ephemeral UI state)
  • Use useLocalStorageState for localStorage persistence

SHOULD

  • Prefer nuqs for URL-shareable state over localStorage
  • Prefer TanStack Query for async operations and loading states
  • Use TypeScript generics for type-safe state: useLocalStorageState<boolean>('key', { defaultValue: false })

AVOID

  • Using for URL state (use nuqs instead)
  • Using for loading/error states (use TanStack Query instead)
  • Using for complex async operations (use TanStack Query instead)
  • Mixing URL state with localStorage without explicit sync logic

Interactions

  • Complements nuqs for URL state management (can sync bidirectionally)
  • Complements TanStack Query for async operations (use TanStack Query for data fetching)
  • Part of state management decision tree (see React rules)
  • Works with React 18+ hooks architecture

Patterns

useSetState Pattern

Use for grouped state that updates together:

typescript
1import { useSetState } from 'ahooks' 2 3const [state, setState] = useSetState({ 4 name: '', 5 email: '', 6 age: 0, 7}) 8 9// Partial updates (shallow merge) 10setState({ name: 'John' }) 11setState(prev => ({ ...prev, email: 'john@example.com' }))

When to use: Form state, game engine state, UI state that changes together (if not URL-shareable)

When NOT to use: URL-shareable state (use nuqs), loading states (use TanStack Query)

useLocalStorageState Pattern

Use for state that persists across browser sessions:

typescript
1import { useLocalStorageState } from 'ahooks' 2 3const [value, setValue] = useLocalStorageState<boolean>('key', { 4 defaultValue: false, 5}) 6 7// Type-safe with generics 8const [settings, setSettings] = useLocalStorageState<Settings>('settings', { 9 defaultValue: { theme: 'light', fontSize: 14 }, 10})

When to use: User preferences, debug flags, settings that should persist across sessions

When NOT to use: URL-shareable state (use nuqs), sensitive data (use secure storage)

Integration with nuqs

Bidirectional sync between URL and localStorage:

typescript
1import { useLocalStorageState } from 'ahooks' 2import { useQueryState } from 'nuqs' 3import { useEffect, useRef } from 'react' 4 5const [queryState, setQueryState] = useQueryState('debug') 6const [storageState, setStorageState] = useLocalStorageState<boolean>('debug', { 7 defaultValue: false, 8}) 9const isFirstMount = useRef(true) 10 11// Sync on mount: localStorage → URL 12useEffect(() => { 13 if (isFirstMount.current) { 14 isFirstMount.current = false 15 if (storageState && queryState !== 'true') { 16 setQueryState('true') 17 return 18 } 19 } 20 // Sync changes: URL → localStorage 21 if (queryState === 'true' && !storageState) { 22 setStorageState(true) 23 } else if (queryState === 'false' && storageState) { 24 setStorageState(false) 25 } 26}, [queryState, storageState, setQueryState, setStorageState])

Use case: Debug flags, feature toggles that should be both URL-shareable and persistent

State Management Decision Tree

  1. URL-shareable state → Use nuqs (filters, search, tabs, pagination)
  2. Grouped state not in URL → Use useSetState (form state, game engine, ephemeral UI)
  3. Async operations → Use TanStack Query (data fetching, mutations, caching)
  4. localStorage persistence → Use useLocalStorageState (preferences, settings)
  5. Simple independent state → Use useState (rare, prefer other options)

References

  • ahooks documentation - Official documentation
  • React rules - State management decision tree and patterns
  • TanStack Query - Async operations and data fetching patterns

Related Skills

Looking for an alternative to ahooks or building a Categories.community AI Agent? Explore these related open-source MCP Servers.

View All

widget-generator

Logo of f
f

widget-generator is an open-source AI agent skill for creating widget plugins that are injected into prompt feeds on prompts.chat. It supports two rendering modes: standard prompt widgets using default PromptCard styling and custom render widgets built as full React components.

149.6k
0
Design

chat-sdk

Logo of lobehub
lobehub

chat-sdk is a unified TypeScript SDK for building chat bots across multiple platforms, providing a single interface for deploying bot logic.

73.0k
0
Communication

zustand

Logo of lobehub
lobehub

The ultimate space for work and life — to find, build, and collaborate with agent teammates that grow with you. We are taking agent harness to the next level — enabling multi-agent collaboration, effortless agent team design, and introducing agents as the unit of work interaction.

72.8k
0
Communication

data-fetching

Logo of lobehub
lobehub

The ultimate space for work and life — to find, build, and collaborate with agent teammates that grow with you. We are taking agent harness to the next level — enabling multi-agent collaboration, effortless agent team design, and introducing agents as the unit of work interaction.

72.8k
0
Communication