Setelah menyimpan keadaan array array kosong
setMessages((previousMessages) => [messageObject, ...previousMessages]);
Vikneswaran G R
setMessages((previousMessages) => [messageObject, ...previousMessages]);