What happens to Class-based Components in Reactjs?
Reactjs Developers, do you guys still remember those class-based components that we used in the earlier days? In the last week, I assist my friend on his freelancing project. The project was to revamp an existing react JS project and when I looked at the code base of the application, I saw those beautiful, elegant class-based components sitting in their components folder 😂.
The moment I saw it, I thought what?? these guys still use class-based components, even from the official reactjs documentation don’t have those class-based components but these guys still use them . Then I got a meeting with the developer and he told me that when he was in the stage of developing this project ( 2018-19 ) the class-based components were in the market and he used them but didn’t get any time to update the project.
But after that meeting, I got into research and looked for why everyone uses functional-based components these days and why class-based components are not in the trend. So here is the research output.
with the release of reactjs 16.3, They introduced Hooks, which are functions that allow functional components to manage state, side effects, and other features that were mainly associated with class components. With the intro of Hooks, developers could use features like useState, useEffect, and others directly in their functional components, making them more powerful and expressive. The move to using functional components and Hooks was motivated by wanting code to be cleaner, and more modular, and to enhance the experience for developers.
Also, Functional components are lightweight and perform better than class components.
So that’s it, and if you are still using the class components, comment why you use them.
Subscribe to my newsletter
Read articles from AHMAD SWALIH directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
AHMAD SWALIH
AHMAD SWALIH
I want to build things that make a difference! That's why I started coding when I was in high school—and why I continue to do so today.