How to set the received messages into single array format

Viewed 23

I want to display the messages from the receiver , when i checked with the console.log(receiveMessages) i'm getting the data as displayed in the below image. But i want data to be set as ["hello", "hello amii"] in a single array , please help me thanks in advance

enter image description here

const [receiveMessages, setReceiveMessages] =  React.useState([]);

socket.on('receive_message', (chatId,msg) =>{
  let newStateMsg = ([...receiveMessages, msg]);
  setReceiveMessages(newStateMsg);
})

useEffect(() => {
 console.log(receiveMessages)
}, [receiveMessages]);
1 Answers
Related