‹ 首页

hook

@darkroomengineering · 收录于 昨天 · 上游提交 昨天

Create reusable React hook (useX pattern). Triggers "create hook", "new hook", "custom hook", "useAuth"/"useScroll"-style names, extracting logic from a component.

适合你,如果你经常封装组件逻辑为自定义Hook

/ 通过 npx 安装 校验哈希
npx oh-my-skill add darkroomengineering/cc-settings/hook
/ 通过 bash 安装
curl -fsSL https://oh-my-skill.com/install.sh | bash -s -- darkroomengineering/cc-settings/hook
/ 已经装过?验证本机副本,不用重装
npx oh-my-skill verify darkroomengineering/cc-settings/hook
安装目标可用 --agent / --scope 或 --to 明确指定;省略时只会在唯一已存在的 agent 目录上自动选择,零命中或多命中会停止并提示。content_hash 缺失或不一致均拒装。
40GitHub stars
~710上下文体积 · 单文件
索引托管

怎么用

商店整理自技能原文 · 版本 fa04efc · 表述以原文为准
它做什么

安装后,当你要求创建自定义 React Hook(如 useX 模式)时,Claude 会根据项目栈(Next.js 或 React Router)自动在对应路径生成 Hook 模板文件,包含类型定义、命名导出等约定。

什么时候触发

当你提到“create hook”、“new hook”、“custom hook”等关键词,或要求创建以“use”开头的 Hook(如“useAuth”)时触发。

装好后可以这样说
触发技能生成 Hook 模板文件
技能会根据项目栈自动匹配路径
支持多种以 use 开头的命名
技能原文 SKILL.md作者撰写 · MIT · fa04efc

Create Custom Hook

Create a custom React hook following Darkroom conventions. The hook itself is stack-agnostic — what differs between satus and novus is the path alias.

Step 1 — Detect stack

Read package.json:

  • dependencies.next → satus / Next.js (path alias @/, no lib/hooks/ requires 'use client' boundary)
  • dependencies["react-router"] → novus / React Router (path alias ~/, components isomorphic)
Step 2 — Choose location

| Stack | Hook path | |---|---| | satus | lib/hooks/<name>.ts | | novus | hooks/<name>.ts (novus puts hooks/ at the project root) |

Confirm by checking the existing lib/hooks/ or hooks/ directory structure if either pattern is unclear from package.json alone.

Step 3 — Emit template
satus / Next.js
// lib/hooks/<name>.ts
'use client'

import { useState, useEffect } from 'react'

interface Use<Name>Options {
  // Hook configuration options
}

interface Use<Name>Return {
  // Return type definition
}

export function use<Name>(options?: Use<Name>Options): Use<Name>Return {
  // Implementation
  return {
    // Return values
  }
}
novus / React Router
// hooks/<name>.ts
// No 'use client' — RR components are isomorphic; the hook runs wherever
// it's called from. If the hook touches browser APIs, guard with
// `typeof window !== 'undefined'` or call from inside `useEffect`.

import { useState, useEffect } from 'react'

interface Use<Name>Options {
  // Hook configuration options
}

interface Use<Name>Return {
  // Return type definition
}

export function use<Name>(options?: Use<Name>Options): Use<Name>Return {
  // Implementation
  return {
    // Return values
  }
}
Conventions (both stacks)
  1. Type everything — options interface, return interface.
  2. Named exportexport function useX, not default.
  3. Prefix with use — React hook naming convention.
  4. No memoization — React Compiler handles it automatically.
Stack-specific

| | satus | novus | |---|---|---| | Directive | 'use client' (hooks live in client boundary) | None (isomorphic) | | Browser API guard | Only runs after hydration anyway | Guard with typeof window or use useEffect | | Path alias | @/ | ~/ |

Before you start

If this hook uses an external library, fetch docs first:

  1. Use Context7 MCP (mcp__context7__resolve-library-idget-library-docs) for the current API.
  2. Run bun info <package> to check the latest version.
Consider Using Hamo

For common use cases, prefer hamo hooks (fetch hamo docs via Context7 first):

import { useWindowSize, useRect, useIntersectionObserver } from 'hamo'

Only create custom hooks when hamo doesn't cover the use case.

Example
User: "create a useLocalStorage hook" (in satus repo)
→ Creates lib/hooks/use-local-storage.ts with 'use client' directive

User: "create a useLocalStorage hook" (in novus repo)
→ Creates hooks/use-local-storage.ts, no directive, browser-API-guarded
Arguments
  • $ARGUMENTS — Hook name (e.g., "useAuth", "useLocalStorage")
按 MIT 许可原样转载,未经改动 · 在 GitHub 查看 →

评论

登录即可评论;带「已验证安装」的,是发布者名下有本店的安装或持有记录。