audit-hooks

Detect and fix forbidden hook and API usage in Next.js apps.

1.8k|375|Updated Jan 15, 2025
One-click install
npx skills add https://github.com/trycompai/comp --skill audit-hooks-trycompai
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: audit-hooks
Source: https://github.com/trycompai/comp/tree/main/.agents/skills/audit-hooks
Command: npx skills add https://github.com/trycompai/comp --skill audit-hooks-trycompai

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Audit and fix hook and API usage patterns across codebases to ensure safe, scalable client/server boundaries.

Core Features & Use Cases

  • Detect forbidden patterns such as useAction from next-safe-action, direct @db usage in client components, raw fetch calls, and post-mutation reloads.
  • Replace with recommended patterns like useSWR for client data fetching, apiClient or serverApi for mutations, and server components for server-side logic.
  • Use cases include modernizing legacy codepaths, hardening client/server boundaries, and preventing stale UI due to improper data fetching.

Quick Start

Audit a project with the skill to automatically identify violations and apply fixes to align with SWR/apiClient/serverApi usage.

Frequently Asked Questions about audit-hooks

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

FAQPage Schema
How do I audit and fix forbidden React hook usage patterns in a Next.js app?

Auditing forbidden React hook usage detects direct database calls, raw fetch, and post-mutation reloads in Next.js client components. It then replaces them with useSWR for fetching and apiClient or serverApi for mutations to enforce safe client/server boundaries.

Why does using useAction from next-safe-action cause stale UI in client components?

Using useAction from next-safe-action can cause stale UI because it bypasses safe cache invalidation. Replacing it with apiClient or serverApi mutations and applying mutate() ensures proper cache invalidation and prevents undefined data guardrail violations.

What's the best way to replace raw fetch calls with useSWR for client data fetching?

The best way to replace raw fetch calls is implementing useSWR for client data fetching. This pattern modernizes legacy codepaths, hardens client/server boundaries, and prevents stale UI by leveraging mutate() for safe cache invalidation.

Can I detect direct @db usage in client components across my codebase?

Yes, you can detect direct @db usage in client components across your codebase. The audit identifies these forbidden patterns and replaces them with server components for server-side logic, ensuring scalable client/server boundaries.

Does this audit tool work with existing Next.js pages and client components?

The audit tool works directly with existing Next.js pages and client components. It scans these files to identify violations like raw fetch and post-mutation reloads, automatically applying fixes to align with SWR and serverApi usage.

When should I not use raw fetch for API calls in React web development?

You should not use raw fetch for API calls in React web development when building scalable Next.js apps. Raw fetch prevents safe cache invalidation; using useSWR with mutate() instead ensures proper data fetching and prevents stale UI.