Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
직접 명령은 검토 Prompt를 거치지 않습니다. 실행하기 전에 소스를 확인하세요.
npx skills add https://github.com/Tryboy869/dojutsu-for-ai --skill react-single-responsibility명령은 한 줄로 유지됩니다. 복사하기 전에 가로로 스크롤해 전체 내용을 확인하세요.
로컬 사본을 원하시나요? SkillsMP에서 현재 제공할 수 있는 파일을 다운로드하세요.
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).SOC 직업 분류 기준