L
L
low molecular macro2022-03-31 11:30:27
JavaScript
low molecular macro, 2022-03-31 11:30:27

Why do many people abandon class components in favor of function components?

At least, this is the impression. Reading articles on React on Medium or somewhere else, very often I come across in them such an idea "leave components on classes in the past. Use only functions". Or even "redesign your projects from classes to functions - the effort will be worth it." I see the same thing in Vue.

The authors give examples and show why functions are more convenient than classes. And, like, with this everything is clear. But here's what's not clear. Why, then, were functions not originally used to create components? I often see examples from 2 or more years ago, and in all these examples, the components are built on classes.

I'm new to React, so I don't know how it has changed over the course of development. But I would like to understand what is causing this trend. Trend change? Or the ability to create components on functions was added to React relatively recently. If this is a new feature, then what was the difficulty in introducing functional components initially?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton, 2022-03-31
@karminski

Why use classes if they will be converted to functions anyway?
Personally, my opinion is that functional components are visually easier to perceive (if not noodles of course), easier to integrate with TypeScript and easier to test.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question