Skip to main content

Design Patterns

Design PatternDefinitionUse Cases
Functional ComponentsSimplify components by using functions instead of classes
  • simple UI elements without complex logic
  • stateless or UI-only components (like buttons, labels)
  • rendering small reusable parts of the UI
Higher-Order Components (HOC)

Functions that take a component and return an enhanced component with additional functionality

  • logging
  • enhancing existing components with additional functionality (e.g., authentication checks)

  • sharing logic between components (e.g., logging, analytics)
  • extending component functionality without modifying the component directly
Render Props

Components with a function as a prop that allows dynamic content rendering based on the function's output

  • sharing stateful logic, such as managing data-fetching
  • toggle or switch functionality (e.g., showing/hiding elements)
  • reusing animation logic across components
Controlled and Uncontrolled Components

Controlled components are fully managed by React state and are preferable for predictable behavior, while uncontrolled components maintain their own state

  • form inputs where fine control over input values is needed (Controlled)
  • simple, self-contained forms with minimal logic requirements (Uncontrolled)
  • cases where validation needs vary based on input type or conditions
Container and Presentational Components

Separates "smart" (container) components, which manage state and business logic, from "dumb" (presentational) components, which focus on rendering UI

  • large applications where separation of UI and logic is beneficial
  • apps using state management (e.g., Redux) or context, where logic and display need decoupling

  • optimizing re-rendering by isolating presentation logic from data handling