Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React App with both Functional and Class components

I know that after the emergence of React Hooks, functional components are able to act almost the same as the class components, and I have seen lately an encouragement wave to use functional components.

My question is, could it hurt in any means to have a hybrid react app with some functional components and some class components? I understand that react would not complain about it, but I am looking for an experienced best practices, did inconsistency with component's types cause any problems?

Any tips are appreciated.

like image 673
Ahmed Hammad Avatar asked May 02 '26 19:05

Ahmed Hammad


1 Answers

After sometime of using a hybrid project, I came to the conclusion that it is better to use functional components for the whole project. Not for any technical reason, but because of the community support.

Many of the packages today are made with functional components only (or mostly) in mind, having class components may require an additional workarounds to make it work.

Some packages creates a short-hand hooks for easier usage, eventually it becomes the official supported way for using the package, like what happened with react-alert.

like image 198
Ahmed Hammad Avatar answered May 04 '26 09:05

Ahmed Hammad