新建Hook
gaia-harness2026-10-27查看 1915复制 1930
使用 Vitest 浏览器模式测试文件搭建一个新的自定义 React 钩子。每当用户要求“创建一个钩子”、“制作一个 useFoo 钩子”、“搭建一个自定义 React 钩子”、“在 app/hooks 下添加一个钩子”,或者描述一段可重用的 React 状态/效果逻辑以保证提取到名为“use*”的钩子中时,请使用此技能。
📘如何使用这个技能
- 1复制技能内容·点击上方「Copy SKILL.md」复制全部内容,或 Download 下载到本地
- 2打开你的 AI 客户端·支持 Claude Code、Trae、Cursor、ChatGPT、DeepSeek、Kimi 等任意 AI 助手
- 3粘贴为系统提示/知识文件·Claude Code:放入 .claude/skills/ 目录;普通对话:作为首条消息发送并说「请严格按这份技能文档执行」
- 4直接提出你的需求·AI 会按技能定义的工作流、格式和约束来处理,无需再解释背景
💡 提示:技能生效后,每次对话只需一句需求,AI 会按 SKILL.md 的流程执行。
SKILL.md971 chars
--- name: new-hook description: Scaffolds a new custom React hook with a Vitest browser-mode test file. Use this skill whenever the user asks to "create a hook", "make a useFoo hook", "scaffold a custom React hook", "add a hook under app/hooks", or describes a piece of reusable React state/effect logic that warrants extraction into a named `use*` hook. model: haiku --- # new-hook ## Workflow 1. Confirm: name (`use-kebab` or `useCamel`), params, return type. 2. Run from the repo root: `./.gaia/cli/gaia scaffold hook <useFoo> [--params "a:string,b:number"] [--returns "ReturnType"]`. 3. Verify: `pnpm typecheck` clean. Open and sanity-check. The scaffold writes `app/hooks/use-<kebab>.ts` (named export `useCamel`) and `app/hooks/tests/use-<kebab>.test.ts`, which renders the hook with async `renderHook` from `vitest-browser-react` and runs in the `browser` Vitest project (real Chromium; run `pnpm install:browsers` once). A bare stub declares a `void` return.