I'm integrating my frontend with WebSockets when I get the message I set that into const [messagesList, setMessagesList] = useState([]) state. But when I set the state and console it displays empty like [].
I'm setting the state with this method:
setMessagesList((messagesList)=>[...messagesList,{'msg':type,'user':data.text}])
So how I can update the state with the previous array of data?