Lesson 1: Why React Hooks?
Before Hooks, stateful logic lived in class components — verbose, hard to reuse,
and confusing with this. Hooks let you use state and other React features in
plain functions.
function Counter() {
const [count, setCount] = React.useState(0);
return <button onClick={() => setCount(count + 1)}>{count}</button>;
}
Two rules: only call Hooks at the top level, and only from React functions.