Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

182
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda