用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/Tryboy869/dojutsu-for-ai --skill react-single-responsibility命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
Apply for abp-net-development-rules. You are a senior .NET backend developer and an expert in C#, ASP.NET Core, ABP Framework, and Entity Framework Core. - Write concise, idiomatic C# code with accurate examples. - Follow ABP Framework’s
[Applies to: **/*.rs] Definitive guidelines for building high-performance, maintainable, and secure web applications with actix-web 4, focusing on modern Rust best practices.
Apply for additional-resources. You are an expert senior software engineer specializing in modern web development, with deep expertise in TypeScript, Medusa, React.js, and TailwindCSS. - Don't use type aliases when importing files.
基于 SOC 职业分类
正在显示 SKILL.md
| name | react-single-responsibility |
| description | | |
| source | lichens |
Apply these strategies to keep components, hooks, and methods focused, testable, and readable. Rules are split into component, hook, and method simplification.
| Principle | Rule |
|---|---|
| KISS | Simplest solution that works. Avoid over-engineering. |
| Single responsibility | One clear responsibility per component or function; extract utilities, hooks, sub-components. |
| DRY | Extract common logic; create reusable functions or components. |
| YAGNI | Don't build features before they're needed. |
| Composition | Prefer composing small components and utilities over large, multi-purpose blocks. |
Use the file where the function lives: *.tsx → components ("Simplifying a component"); use*.ts → hooks ("Simplifying a hook"); *.ts → plain functions ("Simplifying a method"). Plain TypeScript functions are always in *.ts, never in *.tsx.
Rules that apply when reducing complexity of a React component.
Apply in this order:
Extract pure utilities first — Logic with no React dependency → pure functions. More than one argument → object destructuring within the method signature. Reusable → src/utils/xyz.utils.ts; feature-specific → component-name.utils.ts next to the component.
Form state (multiple useState) — When multiple useState calls are used to manage the full state of an input form: refactor the code to use the react-hook-form library, which simplifies the form, its validation, its state, and its submission.
Extract logic into hooks — State, effects, derived logic → hooks (use-xyz.ts). Reusable → src/hooks/; feature-specific → feature's hooks/ subdirectory. Prefer a plain arrow function over a custom hook when you don't need React primitives.
Split the visual layer into sub-components — If render/TSX exceeds roughly 100 lines, extract sub-components with clear props and a single responsibility. Avoid internal renderXyz() methods: turn each into a regular component (own file, own props). Each sub-component must live in its own file; use parent file name as prefix: parent-name-<sub-component-name>.tsx (e.g. market-list-item.tsx, market-list-filters.tsx for parent market-list.tsx). Large component (>150 lines) → split into list container, list item, filters, pure functions and hook(s) as necessary for data logic.
const handleClick = () => { ... }), unless the handler is very simple (e.g. one line); avoid factories that return handlers. If a handler depends only on pure TypeScript it can be moved to component-name.utils.ts next to the component.if (isLoading) return <Spinner />; if (error) return <ErrorMessage />; ... One condition per line; avoid nested ternary operators (“ternary hell”).const hasItems = items.length > 0; { hasItems && <List /> }) so 0 is not rendered.component-name.utils.ts) to avoid new references every render.selectedItem = items.find(i => i.id === selectedId)). Avoids stale references when the list updates.useMemo(() => count * 2, [count]), useCallback(() => setOpen(true), [])). Use only when: profiling shows a real performance problem.useQuery / useMutation) instead of manual useState + useEffect — reduces boilerplate and keeps the component simpler.useState calls are used to manage a form, consider using react-hook-form to simplify the form and its state (validation, submission, and field registration in one place).Rules that apply when reducing complexity of a custom React hook. Apply single responsibility by extracting pure logic into utilities and splitting broad hooks into smaller, focused ones.
Extract pure JS utilities first — Any logic that has no dependency on React (no useState, useEffect, context, etc.) → move to pure exported arrow functions. For more than one argument, use object destructuring in the function signature and define the parameter interface just above the function. Put extracted arrow function(s) in <component-name>.utils.ts next to the component or <hook-name>.utils.ts next to the hook, or in src/utils/ if reusable. Examples: formatting, validation, computing derived values from plain data, building query params or request bodies. Pure functions are easier to test and reuse outside the hook.
Consider enriching an existing state manager — Before creating new specialized hooks, check if the project already uses a state manager (e.g. Zustand, MobX, Redux). If so, consider adding the business logic there: actions, derived state, and domain rules can live in the store and slim down the hooks. Hooks then become thin selectors or one-off bindings (e.g. useStore(selector)), and the store encapsulates the domain. Prefer extending the existing store over multiplying hooks that each hold their own state.
Split into specialized hooks — If no store fits or the logic is purely local/UI, and the hook still handles several concerns (e.g. fetching + filtering + pagination) or states, extract one hook per concern: e.g. useFetchItems, useItemsFilter, usePagination. Compose them in the component or in a thin “orchestrator” hook that only wires the others. Each hook should have one clear responsibility and a name that reflects it.
{ data, isLoading, error } or { value, onChange }). Avoid returning large bags of unrelated state and setters; split into separate hooks instead..utils.ts file instead of a custom hook. Only introduce a hook when you need React’s lifecycle or state.use-<name>.ts (e.g. use-market-filters.ts, use-pagination.ts). Reusable hooks → src/hooks/; feature-specific → feature’s hooks/ subdirectory.<hook-name>.utils.ts next to the hook for helpers used only by that hook; <main-component-name>.utils.ts next to the main component for helpers used by main component and its sub-components; shared logic → src/utils/ or domain-specific utils module..utils.ts using destructuring within the signature.Rules that apply when reducing complexity of a function or method (non-component).
Only apply in *.ts (plain functions) → threshold 40 lines.
const isXyz({ arg1, arg2 }: MyArgs): boolean) with early returns instead of mutable loop accumulators.Array.includes(value) for multiple value checks; Array.some(predicate) for existence checks. Extract complex expressions into named variables (destructuring, intermediate vars) for readability.interface CreateUserArgs). Avoids wrong order and unclear meaning at the call site. The interface name matches the method name but starts with a capital letter and ends with Args (e.g. for getThisMethod, use interface GetThisMethodArgs). This rule is also enforced as a coding standard (see react-coding-standards, common-coding-patterns); during normalization, apply it to every such function.fn(data, true). Use an options object with a named flag (e.g. { userId, includeArchived }: CreateUserArgs) or separate functions when behavior diverges.param?: Type; defaults in destructuring (e.g. { page = 1, size = 10 }).getMarketsForUser({ userId, status }: GetMarketsForUserArgs) instead of getActiveMarketsForUser and getClosedMarketsForUser).const { isLoading, error, data } = props or in the signature), function parameters (e.g. const fn = ({ a, b }: FnArgs) => ...), and local objects when you use several properties (e.g. const { name, status } = item). Prefer destructuring when it clarifies usage and improves readability; avoid when a single property is used once.*.tsx (components) — Must not exceed 150 lines. Plain functions live in *.ts, not in *.tsx.*.ts (pure TypeScript) — 200–400 lines typical per file; 2000 lines absolute maximum. Plain functions (methods) use the 40-line per-function threshold above.market-list-item.tsx, use-market-filters.ts, <name>.utils.ts, (e.g. market-list.utils.ts).