I have a function that generates an object that I would like to add to my state. I am using react hooks. Here is my code:
const [roomMatches, setRoomMatches] = useState({
"user2":{ "percentMatch":"1.0"},
"user3":{ "percentMatch": ".30"}
})
var newMatch = {
survey:{
['percentMatch']: .99
}
}
setRoomMatches([...roomMatches, newMatch]);
My problem is that I keep getting the same error
Uncaught TypeError: roomMatches is not iterable
How can I add to the current state without deleting what is in the state allready?
roomMatchesis an object, but you're trying to spread it into an array.