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

230
Views
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 answers
Answer question

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