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

417
Vistas
React Native Material - How to display loading when button is pressed

I am using React Native Material and i would like to use "loading" when a button is clicked. When the button is not clicked, it should only display the button. Is it also possible when loading is displayed, it will disappear after 5 seconds or when i navigate to a different page?

I have tried to use an if statement when onPress is clicked to display loading but this displays an error.

What i would like when the button is pressed

https://www.react-native-material.com/docs/components/button

Code:

<Button
title="Submit Answers"
onPress={CalculateTotal}
loading
/>
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Create a state variable for loading and set it false. So that whenever navigating to the component from another page, that will disable the loading.set loading true on button click and add a timeout for disabling it.

 const [loading, setLoading] = useState(false);
  
   const CalculateTotal =()=>{
      setLoading(true);
      setTimeout(()=>{
      setLoading(false);
      },5000)
    }

  <Button
   title="Submit Answers"
   onPress={CalculateTotal}
   loading={loading}
 />
about 4 years ago · Juan Pablo Isaza Denunciar

0

You need to create a loading state and change that state according to button press ex:

const [loading, setLoading] = useState(true);
return (
<Button
   onPress={() => setLoading(!loading)}
   title="Submit Answers"
   onPress={CalculateTotal}
   loading={loading}
 />
)
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