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

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

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