Oct 9, 2020
React Hooks vs Class Component
With hooks being introduced, how powerful is it compared to Class components?
Author


Book a call
- Import & Structure: Class components extend from
React.Component(inheritance) and give the component access toReact.Component's functions. This class component should have an only required render() method further to return a React element and call it instead of implementing its own render logic.
- Constructor: You will also see a constructor being used but it’s not mandatory or required to have it in your class as you can get things done without it too. Phew!
- State: React components have a built-in state object where you can store property values of the component. These state objects and their properties can be accessed by this keyword throughout the component. When you want to update the state value, you can do it using setState. But in function, the value of this depends upon how that function is invoked. Before discussing the previous statement, let’s discuss event and event handlers.
- Event and Event handlers: An event is an action that occurs as a result of the user or any other source, such as a mouse click etc. An event handler is a routine that deals with the event.
Suppose you want to handle some event on the click of a button. Your event handler will be something like this:
... and if this is how you call the event handler:
You will get this value as undefined , this is because the handleClick() has lost its component object or this value, i.e. inside the method it cannot identify this reference of the component. Now, this is what I meant when I said it depends on how the function is invoked. Therefore, in order to get the value of this inside the function we need to either:
- Bind the function
2. Or use an arrow function
a) As a callback:
...or
b) In the event handler
In functional components, it's super easy to work because the curse of using this everywhere you use your local variable or call functions doesn't exist. Therefore, no significant use of arrow functions as well. With less code compared to class, it's already a win.
useState hook. Everything else is exactly the same as that of the class.
What are lifecycle methods?
- Mount
- Update
- Unmount
render() is a lifecycle method or not. Of course it is. It occurs between mounting of the component and its update. ComponentDidMountComponentDidUpdateComponentWillUnmount
useEffect().Interesting isn’t it?Let’s find out.
The useEffect() takes two arguments: a callback function and an array of dependencies. The second argument is more interesting. When an empty array is given, it means you want to run an effect and clean it up only once, thereby achieving mount and unmount, but on passing a state variable in the array calls the useEffect() each time the state variable value changes, thus causing an update.
Happy Coding!
Subscribe to Our Newsletter
Subscribe to RSS
Press & Media Hub RSS FeedRelated Articles.
More from the engineering frontline.
Dive deep into our research and insights on design, development, and the impact of various trends to businesses.

Jun 27, 2026
Building a Resilient Hybrid-Cloud Network with WireGuard HA, Route-Based Failover, and Deep Observability

Jun 19, 2026
We Built a 114-Second AWS-to-Azure Failover. Here’s What We Learned

Jun 12, 2026
Cloud-Native and Cloud-Agnostic Are Not Ideologies; They Are Business-Stage Decisions

Jun 8, 2026
Geeklego: The Open-Source Design System Built to Work With AI

May 18, 2026
Your Vibe Code Has No Memory. DESIGN.md Fixes That.

May 14, 2026