React Hooks
React Hooks
4
Lessons
147
Questions
Sample Flashcards from This Course
Here's a preview of what you'll learn:
Q1: 💻 You're building a like button for a blog post. You need it to remember whether the user has liked the post. Which Hook should you use?
A. useEffect
B. useState
C. useContext
D. useReducer
E. useMemo
A: B
Q2: 🔧 Look at this code:
```javascript
function Component() {
const [count, setCount] = useState(0);
if (count > 5) {
const [warning, setWarning] = useState(false);
}
return <div>{count}</div>;
}
```
What's wrong with this code?
A. useState can only be called once per component
B. The Hook is called inside a conditional statement
C. count should be initialized with null instead of 0
D. setCount is not being used in the return statement
E. warning should be defined outside the if block
A: B
Q3: ⚡ A student writes this timer component:
```javascript
function Timer() {
const [time, setTime] = useState(0);
useEffect(() => {
setInterval(() => {
setTime(time + 1);
}, 1000);
}, []);
return <div>{time}</div>;
}
```
The timer shows 1 and then stops. What's the problem?
A: stale closure
Q4: 📊 You're fetching user data from an API when the component loads. Which dependency array should you use?
```javascript
useEffect(() => {
fetch('/api/user')
.then(res => res.json())
.then(data => setUser(data));
}, ?);
```
A. No dependency array (omit the second argument)
B. []
C. [user]
D. [setUser]
E. [fetch]
A: B
Q5: 🎯 Complete the pattern: In useState, the first element of the returned array is the {{1}}, and the second element is the {{2}}.
A: ["current state value", "setter function"]
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