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

161
Visualizações
How make a loading animation while ajax is loading?

How can i show a loading animation while ajax is loading? so far i could make an animation using react loaidng webpack aind now i want it to show when ajax is loading is it possible??

class PersonList extends React.Component {
  state = {
    persons: []
  }

  componentDidMount() {
    axios.get(`https://jsonplaceholder.typicode.com/users`)
      .then(res => {
        const persons = res.data;
        this.setState({ persons });
      })
  }
  render() {
    return (
      <tbody style={{"background":"#c3e6cb"}}>
        {
          this.state.persons
            .map(person =>
        <tr key={person.id}>
          <td>{person.name}</td>
          </tr>
            )
        }
        </tbody>
    )
  }
}

function Preloader(){


    const [data, setData] = useState([]);
    const [done, setDone] = useState(undefined);

    useEffect(() => {
        setTimeout(() => {
            fetch('https://jsonplaceholder.typicode.com/todos/1')
            .then(response => response.json())
            .then(json => {
                setData(json);
                setDone(true);  
            });
        }, 1000);
    })

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

First set in your state when its loading

componentDidMount() {
    this.setState({isLoading: true});
    axios.get(`https://jsonplaceholder.typicode.com/users`)
      .then(res => {
         const persons = res.data;
         this.setState({ persons });
      })
      .finally(() => {
        this.setState({isLoading: true});
      })
  }

Then in your render function take that into consideration

render() {
    return (
        <>
            {this.state.isLoading
              ? <div>**Some loading animation**</div>
              : <tbody style={{"background":"#c3e6cb"}}>
                {
                  this.state.persons
                    .map(person =>
                <tr key={person.id}>
                  <td>{person.name}</td>
                  </tr>
                    )
                }
                </tbody>
           }
         </>
    )
  }
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