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

416
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 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