Two patterns for sharing logic across components.
Higher-Order Components (HOC):
const EnhancedComponent = withAuth(BaseComponent);
Wraps a component to add behavior. Can lead to "wrapper hell."
Custom Hooks:
function MyComponent() {
const { user, isLoading } = useAuth();
}
Share stateful logic without changing component hierarchy.
Modern preference: Hooks are simpler and more composable. HOCs still useful for cross-cutting concerns like error boundaries.