Understanding React Hooks
April 27, 20261 min read
reactjavascript
Understanding React Hooks
React Hooks changed how we write components.
Hooks were introduced in React 16.8. They let you use state and other React features without writing a class.
useState
The most basic hook:
Counter.jsx
import { useState } from 'react';
function Counter() {
const [count, setCount] = useState(0);
return <button onClick={() => setCount(c => c + 1)}>{count}</button>;
}
Never call hooks inside loops, conditions, or nested functions.
Thanks for reading 👋More posts →