hoist-side-effects-to-parents
Installation
SKILL.md
Summary
Handle side-effects (API calls, Routing, Store interactions, Server Actions) in high-level "Container" or "Page" components, and delegate them to "Presentational" components via props or callbacks.
Rationale
- Separation of Concerns: Separates "How things look" (UI) from "How things work" (Logic/Data).
- Testability: Logic layers and UI layers can be tested independently.
- Flexibility: The same UI component can be used with different data sources or actions.
Guidance
- Responsibility:
- Page/Container: Orchestrates data fetching, routing (
useRouter), and global state management. - Presentational Component: Renders data provided by the parent and triggers actions provided by the parent.
- Page/Container: Orchestrates data fetching, routing (
- Boundaries: Keep framework-specific "Magic" (e.g.,
useNuxtApp, Server Actions) in the Container layer.- Next.js: Pass Server Actions as
actionprops to leaf components instead of importing them directly.
- Next.js: Pass Server Actions as
- Delegation: Pass callback functions for actions (e.g.,
onSave,onNavigate) down to children.