The Historical Context: Why Render Props Existed
You'll learn why render props became popular before Hooks were introduced, and what problem they solved in React's evolution.
The Pre-Hooks Era
Before React 16.8 (February 2019), there was a fundamental problem: only class components could hold state. Functional components were stateless "dumb" components that just rendered UI based on props.
This created a dilemma. What if you had stateful logic—like tracking mouse position, managing form state, or handling subscriptions—that multiple components needed? You couldn't just extract it into a function and call it from different functional components, because functional components couldn't use state.
The Solutions That Emerged
The React community developed two main patterns to share stateful logic:
- Higher-Order Components (HOCs) - functions that wrapped your component and injected props
- Render Props - components that accepted a function to control what they rendered, passing data as arguments
Render props became popular because they were more flexible and explicit than HOCs. You could see exactly what data was being shared, avoid prop name collisions, and compose multiple render prop components without "wrapper hell."
Why We Needed an Alternative
Both patterns worked but had downsides: deeply nested components, confusing prop flows, and verbose code. Render props in particular led to callback nesting that resembled the old "callback hell" from pre-Promise JavaScript.
Hooks solved this by letting functional components use state directly, making logic extraction as simple as moving code into a custom Hook function.
Key Takeaway: Render props existed because functional components couldn't use state, and they represented the best available solution for sharing stateful logic before Hooks revolutionized React's composition model.