I usually always write an arrow function and when I need it to be multi-lined then I do "{}". However, I am watching a tutorial, and in it, he is writing this useEffect function:
useEffect(() => {
if (chatId) {
db.collection("chats")
.doc(chatId)
.collection("messages")
.orderBy("timestamp", "desc")
.onSnapshot(snapshot => (
setMessages(snapshot.docs.map(doc=>({
id:doc.id,
data:doc.data()
})))
));
}
}, []);
notice after "snapshot" he has "=> (" not "=> {" and also snapshot.docs.map(doc=>({ where there is a "({" rather than just a "{". Someone help me understand what I am missing here?