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
### [CLEAN-REACT-PATTERNS-2] Let components own their behavior and effects
979
+
980
+
-**Search patterns**: Large prop counts in JSX, props named `*Report`, `*Policy`, `*Transaction`, `*Actions`, `useOnyx`/context results passed directly as props
981
+
982
+
-**Condition**: Flag when a parent component acts as a pure data intermediary — fetching or computing state only to pass it to children without using it for its own logic.
983
+
984
+
**Signs of violation:**
985
+
- Parent imports hooks/contexts only to satisfy child's data needs
986
+
- Props that are direct pass-throughs of hook results (e.g., `report={reportOnyx}`)
987
+
- Component receives props that are just passed through to children or that it could fetch itself
988
+
- Removing or commenting out the child would leave unused variables in the parent
989
+
990
+
**DO NOT flag if:**
991
+
- Props are minimal, domain-relevant identifiers (e.g., `reportID`, `transactionID`, `policyID`)
992
+
- Props are callback/event handlers for coordination (e.g., `onSelectRow`, `onLayout`, `onPress`)
993
+
- Props are structural/presentational that can't be derived internally (e.g., `style`, `testID`)
994
+
- Parent genuinely uses the data for its own rendering or logic
995
+
- Data is shared coordination state that parent legitimately owns (e.g., selection state managed by parent)
996
+
997
+
-**Reasoning**: When parent components compute and pass behavioral state to children, if a child's requirements change, then parent components must change as well, increasing coupling and causing behavior to leak across concerns. Letting components own their behavior keeps logic local, allows independent evolution, and follows the principle: "If removing a child breaks parent behavior, coupling exists."
998
+
999
+
Good (component owns its behavior):
1000
+
1001
+
- Component receives only IDs and handlers
1002
+
- Internally accesses stores, contexts, and computes values
1003
+
- Children follow the same pattern
1004
+
1005
+
```tsx
1006
+
<OptionRowLHNData
1007
+
reportID={reportID}
1008
+
onSelectRow={onSelectRow}
1009
+
/>
1010
+
```
1011
+
1012
+
```tsx
1013
+
function OptionRowLHNData({reportID, onSelectRow}) {
0 commit comments