Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

176
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda