๐Ÿช React

React Hooks Explained โ€” useState and useEffect for Beginners

๐Ÿ“… Jun 8, 2026 โฑ 5 min read

Hooks are functions that give components superpowers. Two of them cover most real work.

useState โ€” data that changes

import { useState } from "react";

function Counter() {
  const [count, setCount] = useState(0);
  return <button onClick={() => setCount(count + 1)}>{count}</button>;
}

Calling setCount re-renders the component with the new value. Never mutate state directly (count++ does nothing visible).

useEffect โ€” side effects

useEffect(() => {
  fetch(`/api/user/${id}`).then(r => r.json()).then(setUser);
}, [id]);   // โ† the dependency array

The dependency array rules

The two rules of hooks

Only call hooks at the top level (never in ifs/loops), and only inside components or custom hooks. Break these and React's state tracking corrupts.

Drill deeper with 50 React interview questions โ€” hooks are Q16โ€“Q30.

โ† All Articles