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

236
Visualizações
Java script arrow function parameter error

I am having an issue where a variable outside of an arrow function is different than the parameter inside the arrow function.

console.log("outside", group);
return (
      <TouchableOpacity style={[styles.itemContainer, { backgroundColor: group.code }]}
        onPress= {group => {
          console.log("inside", group);
          this.navigation.navigate('GroupName', 
            {
              screen: 'Overview',
              params: {gid: group.gid}
            }
          )
        }}
      >
        <Text style={styles.itemName}>{group.group_name}</Text>
      </TouchableOpacity>
);

I am expecting group to be the same inside and outside the arrow function but they are different, specifically the outside group is a object with the parameters group_name, code, and gid while the inside group is a class with a bunch of weird stuff. I have included a picture of the output below.

group value outside and inside arrow function

Why are the two values printed different?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The group in onPress= {group => { defines a new variable called group that really stores information about the click event. If you change the name to event or e or similar the code will work.

console.log("outside", group);
return (
      <TouchableOpacity style={[styles.itemContainer, { backgroundColor: group.code }]}
        onPress= {event => {
          console.log("inside", group);
          this.navigation.navigate('GroupName', 
            {
              screen: 'Overview',
              params: {gid: group.gid}
            }
          )
        }}
      >
        <Text style={styles.itemName}>{group.group_name}</Text>
      </TouchableOpacity>
);
about 4 years ago · Juan Pablo Isaza Relatório
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