N
N
Nikita Andreevich2020-12-23 13:57:08
React
Nikita Andreevich, 2020-12-23 13:57:08

How good practice is it to use both class and function approaches in the same project?

How good practice is it to use both class and function components in the same project? Given that life cycles and other features of both approaches will be used there and there.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Kirill Mager, 2020-12-23
@NikitosAndreevich

From React's point of view, these two components are equivalent . The official React documentation doesn't say anything about plans to deprecate class components in the near future. So you don't have to worry - you don't have to rewrite all the code. But in answer to your question, having studied the documentation of React and Medium, as well as having participated in commercial projects, I want to note that it is good practice to maintain the codebase in the same style as possible. Let not immediately, let it gradually, but the transition to functional components will be correct. Functional components allow you to write code more elegantly.
I advise you to read an interesting recent article , which compares functional and class components and discusses Hooks.
Newer versions of React may start adding features to functional components that are incompatible with class components, leaving the latter at a disadvantage, as was the case with the former before version 16.8.

"We intend to cover every possible use case for classes in hooks, but we will still support class components for the foreseeable future. Facebook has tens of thousands of components written as classes, and we have absolutely no plans to rewrite them. Instead, we are starting to use hooks in new code in parallel with classes" — React documentation

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question