For the last few days, I’ve been working on a small project called Classy Weather. The goal was not to learn something new or modern. The goal was simple, but uncomfortable: understand an old React codebase written using class components.
Until now, I had only worked with function components and hooks. I knew JavaScript classes, so I assumed class components would feel natural. But when I actually started reading and writing this code, I realized something important: knowing JavaScript classes and understanding React class components are two very different things.
This project forced me to slow down, read code carefully, and understand how React used to work before hooks existed.
1. Why I Decided to Go Back to Class Components
In real jobs, you don’t always get to work on fresh, modern codebases. Many companies still have large React apps written with class components. If you can’t read or maintain that code, you are limited as a developer.
So I built Classy Weather, a small weather app using only class components:
- Fetching data from an API
- Saving the last searched location in
localStorage - Showing loading states
- Updating UI when state changes
At first, the code felt strange. Instead of useState and useEffect, everything was happening inside:
state = { ... }componentDidMountcomponentDidUpdatecomponentWillUnmount
I realized that what hooks do for us today, we used to do manually using lifecycle methods.
2. What Confused Me (And What Finally Clicked)
The biggest confusion was mentally mapping hooks to lifecycle methods:
-
useEffect(..., [])→componentDidMount -
useEffectwith dependencies →componentDidUpdate - Cleanup function →
componentWillUnmount
Another hard part was understanding that:
In class components, state is not updated functionally by default. You must think carefully about how and when React re-renders.
But once I followed the data flow in this app:
- User types a location
-
state.locationupdates -
componentDidUpdatedetects the change - Weather is fetched again
- UI re-renders
…everything started making sense.
I also realized something honest about myself:
I was not confused because class components are bad. I was confused because I had never read old React code seriously before.
3. The Real Lesson: Why This Made Me a Better Developer
This project didn’t make me “better at class components”.
It made me better at reading code written by other people.
Now when I look at an old React codebase, I don’t panic. I can understand:
- Where side effects live
- Where state changes happen
- How the component lifecycle flows
- How the UI is derived from state
And that’s the real skill.
Frameworks change. Syntax changes. But the ability to understand existing codebases is what makes you valuable as a developer.
Classy Weather wasn’t about building a weather app.
It was about learning how to think in someone else’s code.
And that’s a skill I know I’ll need in the real world.
Top comments (0)