I have a function that takes in an object called conversation. this conversation object has a unique participant id that I use to fetch a matching participant from my redux state. everything logs fine but when I go to set my contact if the conversation.conversationSid is true, it returns undefined. Am I missing something here? Am I declaring my variables incorrect?
const getContact =(conversation) => {
console.log(conversation) correctly logs the object
let contact = { };
if (conversation?.conversationSid) { // if newSid isnt our defualt
const psidMatch = participants.find(({ sid }) => sid === conversation?.participantSid );
const updatedNumber = psidMatch?.number?.replace("+", " ")
contact = contacts.find(({phone_number}) => phone_number === updatedNumber)
} else {
contact = { firstName: "kevin", lastName: "baker" }
}
console.log(contact) // this is returning undefined if the if statement is true.. if false it logs fine. the main contacts array logs fine...
return contact;
};
contacts array
0: {group: Array(1), _id: '6173cae28a', phone_number: '17705555555', firstName: 'Chad',
1: {group: Array(1), _id: '617b04b75b', phone_number: '18165055555', firstName: 'Barskin',
2: {group: Array(1), _id: '617b04d15b', phone_number: '13039555555', firstName: 'Broski',
updatedNumber if you console.log it right under the replace
13039555555