React Hooks
React Hooks
4
Lessons
147
Questions
Sample Flashcards from This Course
Here's a preview of what you'll learn:
Q1: What does the spread operator (...) do when updating state? `setState({...oldState, key: newValue})`
Q2: 🎮 A game needs to listen for keyboard events when mounted and stop listening when unmounted. Complete the pattern:
```javascript
useEffect(() => {
const handleKeyPress = (e) => { /* game logic */ };
{{1}}.addEventListener('{{2}}', handleKeyPress);
return () => {
{{1}}.{{3}}('{{2}}', handleKeyPress);
};
}, []);
```
Q3: 🎭 You're building a modal dialog. It should show when `isOpen` is true. Fill in the conditional rendering:
`{{{1}} && <Modal />}`
Q4: 📈 You're building analytics tracking. Multiple components need to track events. Where should the tracking context Provider be placed and why?
```
App
├── PublicPages (no tracking)
└── AuthenticatedApp
├── Dashboard (track visits)
├── Settings (track changes)
└── Profile (track views)
```
Q5: 🌐 You're building a search component that should fetch results as the user types. The search query is in state. What dependency should your fetch effect have?
```javascript
const [query, setQuery] = useState('');
const [results, setResults] = useState([]);
useEffect(() => {
fetch(`/api/search?q=${query}`)
.then(res => res.json())
.then(setResults);
}, ___);
```
Sign in to practice all 147 flashcards with spaced repetition!
Lessons
Lesson 1
Lesson 1: Introduction to React Hooks
Learn the fundamentals of React Hooks, including useState and useEffect, to build modern function...
46 questions
Lesson 2
Lesson 2: useState and State Management
Master the useState Hook to manage component state effectively in React applications
39 questions
Lesson 3
Lesson 3: useEffect and Side Effects
Master the useEffect hook to handle side effects, API calls, and component lifecycle in React app...
32 questions
Lesson 4
Lesson 4: useContext and Context API
Learn how to share state across components without prop drilling using React's Context API and us...
30 questions