React queue simulation

It was some time ago since I started learning React, but for some reason I think my code has some obvious errors I can't find. I'm trying to simulate a queue of messages in React: so, whenever you submit a message to the queue, it shows a message of submitting plus a cancel button so you can cancel the message from "submit". But there is a bug: the state of msgQueue is set to a an empty array in the re-render, like if it was the first render: I think it is executing the:
const [msgQueue, setMsgQueue] = useState([])
const [msgQueue, setMsgQueue] = useState([])
line in the beginning of the component, and I don't know why. Any help would be apreciated.
2 Replies
dex
dex9mo ago
In your setTimeout, the filter goes through every queue with the same message then deletes them all, its not unique to one queue. Try using msgId as the filter (assuming its unique)
alfilo
alfilo9mo ago
thanks
Want results from more Discord servers?
Add your server