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

168
Vistas
how to prevent onPress event in react native

How can I prevent function for onPress from running when onLongPress is triggered. Current when I long press after releasing the button onPress is still triggered.

const _handleOnpress =()=>{
  console.log('onPressed triggered')
  // other task only for onPress event
}

const _handleLongPress =()=>{
  console.log('LongPress triggered')
  // other task only for onLongPress event
}

return(
  <Pressable
    onPress={_handleOnpress}
    onLongPress={_handleLongPress}
  >
    <Text>Press me</Text>
  </Pressable>
)
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

When the button is longpress, the onPress function won't be triggered.

But if you want to disabled the onPress function once onLongPress function is triggered, you can set a state to disabled it. Eg:

const [disabled, setDisabled] = useState(false);

const _handleOnpress =()=>{
  if(!disabled){
    console.log('onPressed triggered')
    // other task only for onPress event
  }
}

const _handleLongPress =()=>{
  console.log('LongPress triggered')
  setDisabled(true);
  // other task only for onLongPress event
}

about 4 years ago · Juan Pablo Isaza Denunciar
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