React Hooks Masterclass: useState, useEffect & Custom Hooks
July 30, 2025
.png)
.png)
Why React Hooks Matter?
Replacing class components with functional components using React Hooks is a best practice. Class components are simplified to APIs of functions, and lifecycles, plus this.setState has been replaced with a simple, declarative style. In this masterclass, beyond the syntax, we will deep dive into the insights and real-world importance of hooks like useState, useEffect, and even custom hooks.
Regardless of your role, whether it is within an early-stage startup or running an enterprise-scale application, writing efficient code hinges on an understanding of hooks.
My Journey with React Hooks
When I first started using React Hooks, it felt like switching to a new language. As someone who was deeply comfortable with class-based components, I was hesitant. But within a few weeks of working on a scheduling module for an employee management platform, I realized how much boilerplate I could eliminate.
Suddenly, I was building more with less code. The logic was easier to test, easier to share, and easier to read. And clients noticed our delivery cycles got faster.
useState: Managing Local State, React-Style
What is useState?
useState is the first step into the React Hooks world. UseState allows function components to have their own state without the need to convert them into class components.
Here’s a real-life inspired snippet from a React-based leave tracker we built for an HR client:
jsx :
This state enabled the dropdown for selection of different categories of leaves.
When does it help me?
We had to track users’ temporary selections during development without the need to modify global state. In this case, a simple useState would suffice. No Redux, no context, clean local state only.
Pro Tip from Experience
Using useState to store computed state is not a good practice. If a prop or state can be derived from existing ones, then it should be calculated. Failure to do so will result in hard-to-maintain code and unnecessary re-renders.
useEffect: Bridging the Gap Between React and the Outside World
What is useEffect?
With useEffect, a user can manage side effects such as using an effectful function like fetching data, subscriptions, timeouts, some DOM work, and much more.
Here is an example in an IoT platform’s dashboard in real time:
jsx :
The goal: refresh data from various sensors every 10 seconds. Effect runs once on mount and cleans itself to avoid memory leaks.
A Mistake I Made (So You Don’t Have To)
In one instance, I included a function as a dependency in useEffect, like this:
jsx :
Because fetchData was re-created on every render (it wasn’t memoized), the effect kept firing unnecessarily.
Lesson: If your effect depends on a function, wrap it in useCallback or move it inside the effect.
Custom Hooks: Sharing Logic Without Sharing State
What Are Custom Hooks?
Custom hooks let you abstract reusable logic across components, whether it's fetching data, debouncing input, or integrating with third-party libraries.
Here’s a custom hook we used while building a multilingual marketing site:
jsx :
In every layout component, we now have:
jsx :
This saved us from repeating logic and gave our QA team fewer edge cases to test.
When to Use Custom Hooks
- You’re duplicating the same useEffect logic in multiple places.
- You’re passing down too many props just to reuse behavior.
- You want to extract component logic into a testable function.
Common Mistakes With React Hooks (And How to Avoid Them)
Calling Hooks Conditionally
Don’t do:
jsx :
Instead:
jsx :
- Incorrect Dependencies in useEffect: Don’t guess dependencies—trust the lint rules or use eslint-plugin-react-hooks.
- Using Hooks in Non-Components: Hooks should only be used in React function components or other hooks, not regular JS functions.
React Hooks in Modern Development Teams
For IT Agencies
Hooks simplify onboarding for new developers. You can build reusable UI logic with custom hooks, avoiding prop drilling and redundant Redux setups.
For Startups
You can build MVPs faster with useState and useEffect no need to set up complex state management from day one.
For Enterprises
Hooks power component modularity. You can decouple logic, optimize performance with useMemo, and improve test coverage by isolating state transitions.
React Hooks Benefits
- Less boilerplate
- Better logic reuse
- Fewer bugs due to shared patterns
- Improved readability and testability
- Enables full migration to function components
Final Thoughts
React Hooks are not just syntactic sugar; they are a design philosophy. They encourage developers to think in terms of behavior, not lifecycle.
I’ve worked on several apps, ranging from quick MVPs for startups to robust internal platforms for enterprises, and React Hooks consistently help me deliver faster, cleaner, and more scalable solutions.
Take time to learn them deeply. Write your own hooks. Refactor an old class component. Debug an effect loop. That’s how you become truly fluent in the React Hooks paradigm.