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

139
Visualizações
Display Loading spinner whilst data is fetching

How can show a loading spinner whilst the data is loading to fetch.

const [user, loading, error] = useAuthState(auth);
const navigate = useNavigate()
const [bikes] = useBikes()

if (loading) {
  return  <Loading></Loading>
}
            
fetch(`http://localhost:5000/bike/${id}`, {
    method: 'DELETE'
})
  .then(res => res.json())
  .then(data => {
      console.log(data)
      alert('One Item Deleted')
   });
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

If you have the spinner under the id spinner here's a minimalistic example on how you can do so. just wrap the fetch inside a function.

function delitem(){
  document.getElementByID("spinner").style.display = "block"
  fetch(`http://localhost:5000/bike/${id}`, {
    method: 'DELETE'
    })
    .then(res => res.json())
    .then(data => {
      console.log(data)
      alert('One Item Deleted')
      document.getElementByID("spinner").style.display = "none"
   });
}

about 4 years ago · Juan Pablo Isaza Relatório

0

Put your fetch API inside the useEffect, so you can easily implement your spinner functionality

const [isLoading,setIsLoading]=useState(false);


useEffect(()=>{
 setIsLoading(true);
 fetch("some-url").then(res=>res.json())
  .then(data=>{
  setIsLoading(false)
  console.log(data);
},[])

if(isLoading){
 return <LoadingSpinner/>
}

return <div>..your data </div>
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