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

126
Visualizações
how to show loading bar for few seconds

I want to show the progress bar for 500ms even if its 100%loaded. Current scenario: sometimes the data is arrived so fast the progressbar appears and disappears very quickly. User sometime misses to see it even if it was shown.

tried to use setTimeout(() => ,500) // but didnt work out.

Any logical hints appreciated.

class ABC extends React.Component {
  render() {
    return (
    <>
        {state === Running && (
          <ProgressBar
           minValue={0}
           maxValue={100}
           progress={percentage}
           />
        )}
    </>
    );
  }
}
class ProgressBar extends React.Component {
  render() {
    let percentage = (this.props.progress - this.props.minValue) / (this.props.maxValue - this.props.minValue);
    percentage =  Math.max(Math.min(percentage , 1), 0);
    const fillstyle = { width: (percentage * 100) + "%" };
    return (
      <div className="progressbar" style={this.props.style}>
        <div className="progressbar--fill" style={fillstyle}></div>
      </div>);
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The best way to demonstrate that would be a React functional component with useEffect that starts a timer

Like this:

const ABC = () => {
  const [isTimerRunning, setIsTimerRunning] = React.useState(true);

  React.useEffect(() => {
    let canceled = false;
    setTimeout(() => { 
      if (!canceled) {
        setIsTimerRunning(false)
      }
    }, 500);
    return () => canceled = true;
  }, []);

  return (isTimerRunning || Running) ? (
          <ProgressBar
           minValue={0}
           maxValue={100}
           progress={50}
           />
        ) : null;
}

The cancelation of the timeout is a best practice from React. your component might get un-mounted before the timer executed, and once it's executed it will try to set the state on an unmounted component, leading to an error on react. that's why it's best to make sure you return a function (Will be called by React on unmount) that cancels the "future" execution.

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