🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← 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?

  1. A.tasks.push(item)
  2. B.setTasks([...tasks, item])
  3. C.tasks = tasks + item
  4. 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 →