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

228
Visualizações
Changing the size of a <div> with the value of fetched data

I am fetching data from an api and display some props of them using mapping and I want to change the width of the accordingly with the value of the props.

<h5>
    <span className="viewcount" ref={boxSize}>
    {`View Count: ${item.statistics.viewCount}`}</span>
</h5>

For example, this is a prop called "viewcount" from the api item, and I want the width of this component to be 200px when the viewcount prop is a number of 200. How can I acheive it?

P.S.: I'm using react.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

150 is the default width
<h5>
    <span className="viewcount" ref={boxSize} style={{width: item.statistics.viewCount===200 ? 200: 150}}>
    {`View Count: ${item.statistics.viewCount}`}</span>
</h5>

OR if you want to always set the value of viewCount as the width

<h5>
    <span className="viewcount" ref={boxSize} style={{width: item.statistics.viewCount}}>
    {`View Count: ${item.statistics.viewCount}`}</span>
</h5>

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