In this first part, we will cover the core hooks that every React developer uses almost daily. These include:
useState
useEffect
useContext
useRef
useReducer
We will break down what each hook does, why you should use it, and provide examples that feel practical instead of textbook.
Introduction
React Hooks changed the way developers build components. Before hooks, you had to rely on class components for things like state and lifecycle methods. Hooks made it possible to write everything with simple functions while keeping the code cleaner and easier to reuse.
This cheat sheet is your quick but detailed guide. You can use it as a refresher while coding or as a learning tool if you are new to hooks. Let’s start with the basics.
1. useState
The useState hook lets you add state to a functional component. Think of it as a variable that remembers its value even after re-renders.
import React, { useState } from "react";
function Counter() {
const [count, setCount] = useState(0);
return (
<div>
<p>You clicked {count} times</p>
<button onClick={() => setCount(count + 1)}>Click me</button>
</div>
);
}
useState(0)sets the initial state to 0.countis the current value.setCountis the function to update the value.
Common use cases: form inputs, toggles, counters, or anything where you need to store user interaction data.
2. useEffect
The useEffect hook runs side effects in your component. Side effects are actions that affect something outside the component, like fetching data, updating the document title, or setting timers.
import React, { useState, useEffect } from "react";
function Timer() {
const [seconds, setSeconds] = useState(0);
useEffect(() => {
const interval = setInterval(() => {
setSeconds(prev => prev + 1);
}, 1000);
return () => clearInterval(interval);
}, []);
return <p>Timer: {seconds}</p>;
}
The empty array
[]makes the effect run only once when the component mounts.The cleanup function (
clearInterval) runs when the component unmounts.
Common use cases: API calls, subscriptions, DOM event listeners, or animations.
3. useContext
The useContext hook helps you avoid prop drilling. Instead of passing props through multiple layers, you can use context to share data across the tree.

Join the conversation! Your thoughts help the community grow.