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

172
Views
How to implement percentage increase data from API in React?

I have this problem where I need to fetch data from API and calculate the percentage increase within a certain number of days. Here's the code below...

function Card() {

  const [newEnrollments, setNewEnrollments] = useState("");
  
  const getNewEnrollments = async () => {
   // API call
  };

  useEffect(() => {
    getNewEnrollments();   
  }, []);

  // data returned from API
  // { "new_enrollments": 12248 }  

  return (
    <Wrapper>
      <div className="card1">
        <div className="user">
          <HowToRegRoundedIcon className="icon" />
        </div>
        <div className="card-info">
          <h3>NEW ENROLLMENTS</h3>
          <h4>450</h4>
          <p>
            <BorderLinearProgress variant="determinate" value={90} />
            <span> 90% Increase in 90 Days</span>
          </p>
        </div>
      </div>
      </div>
    </Wrapper>
  );
}

I want to be able to change the hard-coded values in h4(as the value from API), the progress bar, and the span value within 90 days. such that as more data is being updated the values dynamically changes and also the percentage increase.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

If I'm understanding your question correctly, then

<h4>{data_returned_from_api["new_enrollments"]}</h4>

and

<span> {(data_returned_from_api["new_enrollments"] / old_data["new_enrollments"]) * 100}% Increase in 90 Days</span>

should do the trick. You should probably also add some try-catch-statements so that it doesn't crash if the data is missing.

Edit: Obviously, you need to be able to get hold of both the new value and the old value in order to use them. If you don't have both those values, then it is impossible.

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!