Why We Keep Teaching React Class Components

David Barral
Trabe
Published in
3 min readDec 14, 2020
Photo by Carli Jeen on Unsplash

We have been teaching React for several years now, both to our peers at Trabe and to employees of companies that hired our services. Since the introduction of Hooks we have adapted our courses for beginners. As of now we start by teaching Function Components, then we jump to Class Components, and lastly, we introduce Hooks.

In March 2019, I came upon a tweet that started a very interesting thread (I’ve wanted to write about this for months, never got the time. It’s still relevant, though 😌):

One particular answer, from Kent C. Dodds, a very well known figure in the React community, caught my eye:

Wow! That’s ballsy! But don’t freak out yet. He later elaborated to say that, given time restrictions, he’d rather teach Hooks and let people learn Class Components by themselves.

Personally, I agree with his logic. We mainly use Hooks in new projects and is hard to remember the last time I wrote a Class Component (outside of Error Boundaries and legacy codebases). It seems fair to teach just the things you will need the most. You still have plenty of resources to learn the whole picture by yourself.

So, why we keep teaching them? 🤔

Reasons to keep teaching Class Components

I think the main reasons we keep teaching class components are the following:

  • Error Boundaries. There is no alternative to that based on Hooks. It would be a “just trust me” moment.
  • “Legacy” applications. There are too many applications that still use Class Components. That’s not legacy code yet (not for the React official docs at least). Using class components in 2020 can’t be seen as technical debt.
  • Third-party libraries. There are tons of them that still use Class Components. To evaluate, understand, debug, and even fix them, you need the knowledge. Not using something does not mean it’s less relevant. I don’t use Typescript, but learned enough to handle myself around Typescript codebases.
  • Not everybody uses Hooks yet, so we don’t know for sure what kind of projects our students will end up working on. They could lack the knowledge to do their jobs if we skip Class Components.
  • Lots of programmers struggle with closures and the JavaScript execution model. They are much more comfortable with classes (maybe because they have strong OO backgrounds).
  • It can be a consequence of the previous point but, in our experience, people tend to understand Hooks lifecycle easier when comparing it to the Class Components one, although Dan Abramov has heard otherwise 😄 (yes, yes, side-by-side is not the same as one-after-the-other).
  • And lastly, but quite important, the people that hire us want us to cover React in full and not skip Class Components.

Reasons to not keep teaching them

Well, for now, we only have found weak reasons to not teach them:

  • Kent’s reason: you can skip them in a course and give the students resources to learn that themselves. However, the point of courses is to reduce the entry barrier to the technology, leaving them aside does not help to reduce that barrier.
  • Encourage people to use Hooks instead of Class Components presenting them as the only option. However, we prefer the “Choose for yourself. We strongly recommend it though” discourse. It reduces friction.

What’s your take?

Teaching people is hard. It’s also a great responsibility so we do not take this lightly.

We are quite interested in seeing other people’s approaches regarding this matter. The opinions on these tweets are all valid points. If you, like us, teach React to other developers, please leave a comment with your take. I will appreciate it 😊.

--

--

David Barral
Trabe
Editor for

Co-founder @Trabe. Developer drowning in a sea of pointless code.