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

242
Views
How to Modify CSS Module Style via Javascript

I'm fairly new to javascript and react, but I'm diving in and creating my first react app.

I'm tying to modify the amount of "gridTemplateRows" that display on my screen via a variable and modify it with a new numbers based on the results from the list (I've hard coded this as a 6 right now), however I'm using CSS Modules and i can't seem to get the grid to change its row count and display properly.

Component Code

import classes from "./TimeSlot.module.scss";
import AvailabilityCalendarData from "../../../../../FakeDB/AvailabilityCalendarData";

function TimeSlot() {
  const addTimeSlot = () => {
    document.getElementsByClassName(
      `${classes.time_interval}`
    ).styles.gridTemplateRows = "repeat(6, 1fr)";
  };

  const timeSlotRow = AvailabilityCalendarData.map((timeSlot) => (
    <div key={timeSlot.id}>{timeSlot.startTime}</div>
  ));

  return (
    <div className={classes.time_interval} onLoad={addTimeSlot()}>
      {timeSlotRow}
    </div>
  );
}

export default TimeSlot;

CSS

.time_interval {
  grid-area: time;
  display: grid;
  grid-template-rows: repeat(17, 1fr);
  font-size: 14px;
  & > div {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    box-shadow: inset 0 1px 0 0 #eceff1;
  }
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Just set the style:

<div className={classes.time_interval} 
  style={{ gridTemplateRows: `repeat(${timeSlotRow.length}, 1fr)` }}
>{timeSlotRow}</div>

Or you could take a look at grid-auto-rows.

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!