Token导航 LogoToken导航TokenDH.com
研究检索需要联网github未标认证来源可访问许可证需确认审计通过

react-single-responsibilityReact single responsibility 搜索

Agent Skill

用于辅助前端页面、组件、样式和交互逻辑的开发与维护。它适合让 Agent 生成或审查 React、Next.js、Vue、Tailwind、CSS 等相关代码,整理组件结构,或定位布局和性能问题。使用时需要结合项目现有设计系统、路由和构建方式,避免只生成孤立片段;涉及页面改动时,应配合本地预览和构建检查确认视觉效果。

总安装

432

周安装

18

GitHub Stars

公开资料未说明

下载量

144
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:react-single-responsibility(React single responsibility 搜索)
来源仓库:https://github.com/lichens-innovation/ai-dev-tools
仓库路径:skills/react-single-responsibility
安装命令:
npx skills add https://github.com/lichens-innovation/ai-dev-tools --skill react-single-responsibility
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/lichens-innovation/ai-dev-tools --skill react-single-responsibility

简介

用于辅助 React、Next.js、Vue 等前端框架的开发与维护。

  • 适用于 Codex、Claude、Cursor、Gemini CLI,通过 GitHub 安装。
  • 适合生成或审查组件结构、样式和交互逻辑代码。
  • 使用时需结合项目设计系统和构建方式,避免孤立片段。
  • 页面改动后应配合本地预览确认视觉效果。

SKILL.md

Single Responsibility — Simplify Components & Methods

Apply these strategies to keep components, hooks, and methods focused, testable, and readable. Rules are split into component, hook, and method simplification.


Principles

PrincipleRule
KISSSimplest solution that works. Avoid over-engineering.
Single responsibilityOne clear responsibility per component or function; extract utilities, hooks, sub-components.
DRYExtract common logic; create reusable functions or components.
YAGNIDon't build features before they're needed.
CompositionPrefer composing small components and utilities over large, multi-purpose blocks.

Which rules apply

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.


Simplifying a component (filename pattern *.tsx)

Rules that apply when reducing complexity of a React component.

Decomposition (avoid God Component)

Apply in this order:

  1. 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.
  2. 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.
  3. 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.
  4. 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.

Structure and readability

  • Order inside the component: types → state → computed const → effects → handlers → render.
  • Handlers: If a handler depends only on pure TypeScript it can be moved to component-name.utils.ts next to the component; otherwise, if the handler is very simple (e.g. one line) keep it inline in the onClick or other event props; finally, if the handler is more complex or involves state, use one arrow function per handler (e.g. const handleClick = () => {...}). Always avoid factories that return handlers (double arrow functions).
  • Early returns in render — Keep the main path flat: if (isLoading) return <Spinner />; if (error) return <ErrorMessage />;... One condition per line; avoid nested ternary operators (“ternary hell”).
  • Boolean in JSX — Use explicit computed boolean (e.g. const hasItems = items.length > 0; {hasItems && <List />}) so 0 is not rendered.
  • Static data — Constants and pure functions that don't depend on props or state → outside the component (relocate into component-name.utils.ts) to avoid new references every render.

React-specific

  • Selected items — Store selection by ID in state; derive the full item from the list (e.g. selectedItem = items.find(i => i.id === selectedId)). Avoids stale references when the list updates.
  • useMemo / useCallback — only when absolutely necessary — Default: do not use. Re-renders are often an acceptable tradeoff to promote readability. These hooks add complexity and recent React compilers already optimize renders. Avoid for trivial cases (e.g. useMemo(() => count * 2, [count]), useCallback(() => setOpen(true), [])). Use only when: profiling shows a real performance problem.
  • Data fetching — Prefer TanStack Query (useQuery / useMutation) instead of manual useState + useEffect — reduces boilerplate and keeps the component simpler.
  • Form state — When multiple 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).

Simplifying a hook (filename pattern use*.ts)

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.

Decomposition order

  1. 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.
  2. 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.
  3. 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.

Hook design

  • Narrow return shape — Prefer returning a small, stable object (e.g. {data, isLoading, error} or {value, onChange}). Avoid returning large bags of unrelated state and setters; split into separate hooks instead.
  • Plain function vs hook — If the logic doesn’t need React primitives (state, effects, context), use a plain function in a .utils.ts file instead of a custom hook. Only introduce a hook when you need React’s lifecycle or state.
  • Dependencies — Keep hook inputs explicit (parameters); avoid reading from context or globals inside the hook unless that’s the hook’s sole purpose. Easier to test and reason about.

File and naming

  • One hook per file when the hook is non-trivial; file name: use-<name>.ts (e.g. use-market-filters.ts, use-pagination.ts). Reusable hooks → src/hooks/; feature-specific → feature’s hooks/ subdirectory.
  • Co-locate utilities<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.

Quick checklist (hooks)

  • Does the hook contain logic with no React dependency? → extract to pure arrow functions in .utils.ts using destructuring within the signature.
  • Does the hook do more than one thing? → consider enriching the project’s state manager (Zustand, MobX, etc.) first; otherwise split into smaller pure JS utilities, or specialized hooks (e.g. fetch vs filter vs pagination) and compose.
  • Could this be a plain function? → if it doesn’t need state/effects/context, use a utility instead of a hook.
  • Is the return type a large, mixed bag? → consider splitting the hook or returning a smaller, focused API.

Simplifying a method (filename pattern *.ts)

Rules that apply when reducing complexity of a function or method (non-component).

Long function (>40 in *.ts)

Only apply in ***.ts (plain functions) → threshold 40 lines**.

  • Signal: Scrolling to understand a single function.
  • Fix: Extract into smaller, named arrow functions. Apply single responsibility: each new method must stay simple and focused on one task only (e.g. validate → fetch → persist → notify). Each step should be testable in isolation.

Control flow

  • Early returns — Prefer early returns over nested if/else (max ~2 levels of nesting).
  • const over let — Prefer const; use reduce or pure helpers (e.g. const isXyz({arg1, arg2}: MyArgs): boolean) with early returns instead of mutable loop accumulators.
  • Clear conditionals — Use Array.includes(value) for multiple value checks; Array.some(predicate) for existence checks. Extract complex expressions into named variables (destructuring, intermediate vars) for readability.

Parameters

  • Long parameter list (>1 param)As soon as a function or method has more than one parameter (2+ arguments), use a single params object with destructuring and extract the parameter interface immediately above the function signature (e.g. 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.
  • Interface used only for one method — When an interface exists solely to type a single method’s signature, place it immediately above that method (colocation). This self-documents the signature that follows and keeps the type next to its only consumer.
  • Boolean flag parameter — Avoid fn(data, true). Use an options object with a named flag (e.g. {userId, includeArchived}: CreateUserArgs) or separate functions when behavior diverges.
  • Conventions — Destructuring for multiple params; extract parameters into named interfaces; optional as param?: Type; defaults in destructuring (e.g. {page = 1, size = 10}).

Duplication (DRY)

  • Signal: Copy-paste with minor variations.
  • Fix: Extract a parameterized arrow function (e.g. single getMarketsForUser({userId, status}: GetMarketsForUserArgs) instead of getActiveMarketsForUser and getClosedMarketsForUser).

Shared (components and methods)

Object destructuring

  • Use object destructuring when reading or passing object attributes so that attribute names are explicit and the code stays readable. Applies to: component props (e.g. 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.

Coupling (shotgun surgery)

  • Signal: One feature change requires edits in many files.
  • Fix: Co-locate related logic (e.g. feature folder with its own components, hooks, utils, types); reduce coupling and centralize domain logic where it belongs.

File and size guidelines

  • ***.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.
  • File names: kebab-case. Examples: market-list-item.tsx, use-market-filters.ts, <name>.utils.ts, (e.g. market-list.utils.ts).

Quick checklist

  • Does it do more than one thing? → if yes: extract pure utilities, hooks, or sub-components (component) or smaller named functions (method).
  • More than 1 parameter? → always use a single options object, an extracted parameter interface immediately above the signature, and destructuring (applies to every function with 2+ args; see also react-coding-standards).
  • Copy-pasted code? → extract and parameterize.
  • Control flow deeply nested? → use early returns and intermediate variables.
  • Comments explaining *what*? → rename for self-documenting code; keep comments for *why* only.

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

38.65%
按下载量换算56

Claude

28.55%
按下载量换算41

Cursor

18.91%
按下载量换算27

Gemini CLI

9.52%
按下载量换算14

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

需要联网

该 Skill 可能需要联网访问来源站点、仓库或外部 API;具体网络访问范围需要结合源码和 README 复核。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills