React Component Structure Guidelines #1657
ygrishajev
started this conversation in
Contribution RFC
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
These guidelines help ensure maintainable, testable, and scalable React code.
They should be followed when contributing new components or refactoring existing ones.
✨ Core Principles
Keep components small and focused
A component should do one thing. If it's hard to name, it's probably doing too much.
Minimize hooks in the view layer
Use custom hooks or container components to isolate logic.
Prefer composition over configuration
Avoid deeply nested components with complex props. Compose smaller units instead.
Keep logic out of UI components
Views should be mostly dumb and receive props. Business logic and state should live in containers, hooks, or services.
🔹 Recommended Patterns
1. Container Patterns
We support two common patterns for containers:
A. Container + View
B. Function-as-Children Container
This pattern is useful when the consuming component needs fine-grained control over rendering but benefits from shared data-fetching and state logic.
2. Hook Extracted for Logic
3. Service Layer Composition
4. Isolate UI-Only Logic
Some UI concerns are complex enough to deserve their own abstraction — especially if they involve:
A common example is tab management. Tabs should not live inside business logic containers or views tied to domain data. Extract this kind of behavior into a reusable hook or wrapper component:
Keeping UI-only logic separate prevents pollution of views and containers and improves readability, reusability, and testability.
🔧 Practical Tips
✅ Summary Checklist
Use this checklist as a quick reference during implementation or review:
Beta Was this translation helpful? Give feedback.
All reactions