Po przechowywaniu stanu tablicy jest pusty

setMessages((previousMessages) => [messageObject, ...previousMessages]);
Vikneswaran G R