Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

119
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!