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

275
Visualizações
Why Linking.openURL fires automaticaly without TouchableOpacity?

i have a problem with function in React Native. I checking if the String is e-mail, text or phone and returns appropriate object, e.g Linking.openURL(mailto:${phone}).

But function automatically fires the URL and forwarding me to Phone Application, what im doing wrong?

A function to check value in a String

function checkResult(result){
  let emailChecker = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
  if( !( emailChecker.test(result))){
    return Linking.openURL(`mailto:${result}`)
  }

  if(isNaN(result)){
    return Linking.openURL(`tel:${result}`)
  }
}

My touchableOpacity

<TouchableOpacity
        onPress={checkResult(result)}
        >
        <Text
          style={{
            color: 'blue',
            fontSize: 20,
            marginTop: 10,
            marginBottom: 40,
          }}
        >
          {result}
        </Text>
        </TouchableOpacity>
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

onPress={checkResult(result)} this will result in calling the function checkResult when you pass it to the component, so the function will execute on render.

Update your onPress callback to () => checkResult(result).

<TouchableOpacity
  onPress={() => checkResult(result)} 
>
  <Text
      style={{
      color: 'blue',
      fontSize: 20,
      marginTop: 10,
      marginBottom: 40,
    }}
    >
      {result}
    </Text>
</TouchableOpacity>

for more details on passing function to component - here

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