Unhandled Rejection (TypeError): Cannot read property 'senderemail' of undefined
aniruddhac99 opened this issue ยท 3 comments
aniruddhac99 commented
arihant-jain-09 commented
When did you faced this issue?
const channelRef=firestore.collection('servers').doc(currentserverid).collection('channels').doc(id).collection('messages');
const query=channelRef.orderBy('createdAt','desc').limit(1);
const [messages]=useCollectionData(query,{idField:'id'});
the above code gets the latest message, I have used react-firebase-hooks to get messages and then query to limit to 1.
You may see image link included for firestore database architecture..
if(messages[0].senderemail===auth.currentUser.email){
const messageRef=channelRef.doc(messages[0].id);
await messageRef.update({
message:messages[0].message+'\\n'+formValue
},{merge:true})
}
arihant-jain-09 commented
I just cloned my repo and did not faced any error
aniruddha-chakravarty commented
I just cloned my repo and did not faced any error
Just fixed the issue. ๐
Added an Optional Chaining Operator in line 56 of ChatSearchBar.jsx file, just after messages[0]