#How to update state of an Array inside Object

4 messages · Page 1 of 1 (latest)

jagged cargo
#
const [recording, setRecording] = useState({
    events: [], startTime: -1, htmlCopy: ""
  })

setIsRecording((prevRecording) => ({
        ...prevRecording,
        events:[...prevRecording.events, {name: "a"}],
      }));

I was getting an error of TypeError: prevRecording.events is not iterable

I don't understand because, events is an array

normal nacelle
#

Hi @jagged cargo , there is a typo in your code. The const you've declared has a setRecording function but when you run the function you write setIsRecording. Maybe this typo is causing the error?

jagged cargo
#

Ah thank you.

#

I overlooked my code, thank you so much. I didn't notice it.