Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

175
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda