Agent skill
tsx-modular-component-pattern
Guide for outputting React/TSX components by prioritizing reusable sub-components, controlling length, and declaring them as const before the main component to ensure clear structure and maintainability.
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/design/tsx-modular-component-pattern
SKILL.md
Component Structure
When generating React/TSX components, follow these structural points to maintain information focus under Primacy/Recency:
- Decompose logically related UI modules into independent sub-components, ensuring each handles a single responsibility.
- Declare all sub-components as
constbefore the main component, making dependency order clear at a glance. - Keep each sub-component within 30-40 lines, continue decomposing to finer granularity if needed.
- Use semantic naming (e.g.,
VideoOverlay,ActionButton,CreatorInfo) for quick retrieval and reuse. - Use Props to clarify data and event flow, let main component only handle assembly and state dispatch.
- Regularly review if sub-components can be extracted to shared directory to avoid duplicate implementations.
Reference example:
// Sub-components defined first
const PlayOverlay = ({ isPlaying, onToggle }: PlayOverlayProps) => (
<div className="...">...</div>
)
const ActionButtons = ({ likes, comments }: ActionButtonsProps) => (
<div className="...">...</div>
)
// Main component uses sub-components
export function VideoFeed({ videos }: VideoFeedProps) {
return (
<div>
{videos.map(v => (
<PlayOverlay ... />
<ActionButtons ... />
))}
</div>
)
}
Final confirmation: Main component handles orchestration, sub-components handle details, achieving a stable pipeline of "decompose first, then compose".
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?