When You'll See Classes: Legacy Codebases and Error Boundaries
What you'll learn: Where class components still exist in modern React development and why they haven't completely disappeared.
The Reality Check
Even though function components are now the standard, you'll still encounter class components in the wild. Understanding where and why helps you know what you're looking at—and when you might need to write one yourself.
Three Common Places Classes Appear
1. Legacy Codebases
Any React project started before 2019 (when Hooks arrived) was built entirely with classes. These codebases still exist and still need maintenance. You might join a team working on one, or migrate parts of it to modern patterns.
2. Error Boundaries
This is the only feature that currently requires a class component. React hasn't yet provided a Hook-based way to catch errors in child components. If you need to gracefully handle component crashes, you'll write a class with componentDidCatch and getDerivedStateFromError lifecycle methods (concepts you'll learn soon).
3. Third-Party Libraries
Some npm packages were written years ago and still export class components. When you use them, you're consuming classes even if you never write one yourself. Popular older libraries might not have been updated to function components.
Why Not Rewrite Everything?
The same reason you don't rewrite all working code: if it works, it works. Classes aren't broken—they're just no longer the preferred approach for new code.
Key Takeaway: Class components live on in legacy projects, Error Boundaries (the one thing Hooks can't do yet), and older third-party libraries. You won't write many, but you'll definitely read them.