← Quiz: React Basics: all 10 questions
Quiz: React Basics · Question 2 of 10
How should you add an item to a state array tasks?
How should you add an item to a state array tasks?
- A.tasks.push(item)
- B.setTasks([...tasks, item])
- C.tasks = tasks + item
- D.setTasks(tasks.push(item))
Answer & explanation
Correct answer: setTasks([...tasks, item])
Create a new array so React notices the change.
Can you get the rest right without peeking?
Take the timed Quiz: React Basics quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →