You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: skills/react-clean-architecture-add-component/references/component-architecture.md
+62-2Lines changed: 62 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,13 +2,46 @@
2
2
3
3
This reference defines classification, file layout, and dependency direction in `src/components`.
4
4
5
+
## Design Intent and Principles
6
+
7
+
The goal of this skill is not only to add React components, but to apply the Container/Presentation pattern consistently with clear separation of responsibilities and dependency direction.
8
+
9
+
This reference does not define full application-wide architecture. It focuses on design quality at the component boundary.
10
+
11
+
- Separate rendering responsibilities from logic responsibilities.
12
+
- Do not place state management, side effects, or business decisions in the presentation layer.
13
+
- Avoid mixing responsibilities across boundaries and keep dependency direction explicit.
|`container`| Handles state management, side effects, event handling, and data fetching. |`index.tsx`, `use<ComponentName>.tsx`, `types.ts`|
38
+
|`presentation`| Receives props and renders UI only. Must not perform external I/O or state updates. |`presentation.tsx`, `presentation.module.scss`, `presentation.stories.tsx`|
39
+
40
+
Notes:
41
+
42
+
-`ui` is composed of presentation only.
43
+
-`features` must separate container and presentation.
44
+
12
45
## Reclassification Rule
13
46
14
47
If the user requests `ui` but the implementation contains any of the following, treat it as `features` and ask for confirmation before creating files:
@@ -39,6 +72,32 @@ Ask using these options:
39
72
- Presentation receives props and handles rendering only.
40
73
- Keep logic in `use<ComponentName>.tsx`.
41
74
75
+
### Container/Presentation Separation Rules (Anti-patterns and Decision Examples)
76
+
77
+
Principles:
78
+
79
+
- Container is responsible for state management, side effects, event interpretation, and async processing.
80
+
- Presentation is responsible only for rendering from received props.
81
+
- Keep business decisions and data transformation in container-side code, not in presentation.
82
+
83
+
Placement rules:
84
+
85
+
- Place in container: `useState` / `useReducer` / `useEffect`, API calls, context/store read-write, business rule application.
86
+
- Place in presentation: JSX rendering and display-only branching (for example: empty, loading, error views).
87
+
- Use `types.ts` to define I/O contracts between container and presentation.
88
+
89
+
Anti-patterns:
90
+
91
+
- Calling APIs or mutations from presentation.
92
+
- Updating context/store directly from presentation.
93
+
- Implementing business decisions (authorization checks, state transition decisions, data shaping) in presentation.
94
+
- Splitting files formally while keeping practical logic in presentation.
95
+
96
+
Good / Bad examples:
97
+
98
+
- Bad: `presentation.tsx` fetches data and manages loading state directly.
99
+
- Good: `use<ComponentName>.tsx` manages data fetching and state, and `presentation.tsx` renders only from props such as `isLoading`, `items`, and `onAction`.
0 commit comments