🌐React Hooks
Also known as Hooks (React), useState, useEffect, React Hook
Small React tools whose names start with use. useState lets a part of the page keep a value.
Think of it like
It is like a toy with snap-on parts. Snap one on, and the toy can do a new trick.
Example
Jack's Like button must count clicks. He adds useState(0), and each click calls setLikes to raise the number on screen.
Why it matters
Definition
Example code
jsx
const [likes, setLikes] = useState(0);
return <button onClick={() => setLikes(likes + 1)}>{likes}</button>;Common mistake
Key takeaways
- 1Names start with use. useState, useEffect, useRef.
- 2Top level only. Never inside an if or a loop.
- 3Make your own. Combine hooks into a new one.