Wrapper Hell and HOCs
What you'll learn: How reusing stateful logic in class components led to deeply nested, hard-to-read component trees.
The Problem: Sharing Logic Between Class Components
Before Hooks existed, class components had no clean way to share stateful logic. If you needed authentication logic, data fetching, or theme context in multiple components, you couldn't just "mix it in." Classes can only extend one parent, and lifecycle methods are tied to the component instance.
The Solution That Created a New Problem
Developers used Higher-Order Components (HOCs) — functions that take a component and return a wrapped, enhanced version:
// HOC adds user data to any component
const withUser = (Component) => {
return class extends React.Component {
// lifecycle logic here
render() {
return <Component user={this.state.user} {...this.props} />;
}
};
};
export default withUser(MyComponent);
This worked, but applications often needed multiple HOCs per component (auth, theme, routing, data, etc.). Each HOC wrapped the previous one, creating deeply nested trees.
Wrapper Hell: The Consequence
Your component tree in DevTools looked like this:
<WithAuth>
<WithTheme>
<WithRouter>
<WithData>
<MyActualComponent />
Debugging became a nightmare. Props flowed through five layers. Finding where logic lived required tracing through multiple files. This pattern was nicknamed "wrapper hell" or the "pyramid of doom."
Key Takeaway: Class components required HOCs to reuse stateful logic, which led to deeply nested component trees that were hard to debug and maintain—a problem modern Hooks elegantly solved.