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

173
Visualizações
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 Respostas
Responde à pergunta

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 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