Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

175
Views
if else statement returning undefined with redux state

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
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!