Exploring the integration of Dynamic Values in React-JSS

Our team is integrating a CSS library into our React project. Check it out here: https://cssinjs.org/react-jss/?v=v10.1.1#dynamic-values.

I am currently working with two dynamic values in this way:

import React from 'react'
import {createUseStyles} from 'react-jss'

const useStyles = createUseStyles({
  duration: (height, marginTop) => ({
    marginTop: marginTop,
    height: height
  })
});

const Appointment = ({companyName, vehicleId, duration, isHalfHour=false}) => {
  const height = (duration / 0.6).toString().concat('%');
  const marginTop = isHalfHour ? '20px' : '0';  
  const classes = useStyles(height, marginTop);

  return (
    <div className={classes.duration}>
      Sample Text
    </div>
  )
};

Initially, the system worked fine when only the height variable was used. But now that I'm trying to include the marginTop value as well, it seems to be ignored.

Even hardcoding like this didn't fix the issue:

const classes = useStyles(height, '20px');

I'm puzzled about what could be causing the second parameter in the duration style not to be applied correctly. Any insights are appreciated!

Answer №1

Right before going to bed, I decided to give it one more shot: I couldn't figure out why the first parameter was working but the second one wasn't. So, I made a change by renaming the parameter to props and passed in: {height, marginTop}. To my surprise, it finally worked!

What a day!

Answer №2

When using the useStyles(object) function, only a single argument should be passed.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Addressing rendering problems in Ag-GRID when used with Angular

I'm facing a perplexing issue where the ag-grid table in my Angular 12 / Bootstrap 5 application renders with a height of 0px. Below is the link to the rendered table: rendered table Upon inspecting with Chrome's debug tool, I noticed that the ...

How can I find the distance between two sets of coordinates using JavaScript?

My current task involves calculating the distance in kilometers between two sets of latitude and longitude coordinates, with the goal of displaying this distance in a label or paragraph on a webpage. I have an address from which I can determine the lat1 ...

Experiencing problems with the CSS on the Login page and have yet to find a solution

Description:- I encountered an issue with my HTML login page where I used an image for the username and password. Everything worked fine when I manually typed in the username and password, but when I selected the username from the auto-fill suggestions pop ...

What is the best way to enhance a react-bootstrap component with TypeScript?

Currently, I am utilizing <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="6f1d0a0e0c1b420d00001b1c1b1d0e1f2f5e415f415f420d0a1b0e415e5b">[email protected]</a> and delving into the development of a customized Button ...

Using React to iterate through a map and render various components

There's a unique scenario I'm facing, In my current environment, I don't have a standard list structure that allows me to map through and display components in each iteration, like this: list.map(shape => <Shape {...shape} />) In ...

The NextUI <Navbar> element is not remaining fixed at the top of the page

Currently, I am assisting an individual who is unfamiliar with React, Next, or Tailwinds to enhance the responsive design of their project. Previously, they incorporated NextUI components in certain areas. As part of my refinements to the navbar, I opted ...

next.js: useEffect executed twice when utilizing parameter from the router

Here is my code snippet: const router = useRouter(); const { pid } = router.query; useEffect(() => { setLoading(true) fetch('my/endpoint/' + pid) .then((res) => res.json()) .then((data) => { ...

hint.css guide for inserting line breaks into hints

Is there a way to manually insert line breaks in Hint.css hints? I've attempted using <br>, \n,, and various combinations of them. I've also experimented with the following CSS properties: white-space: normal; word-wrap: break-word; ...

What could be the reason that the height: auto property is not creating a content area big enough to accommodate my content

When a user is not logged in, the header displays a logo and a login form that requires ample space. Once the user logs in, the full navigation menu appears in a smaller header size. To achieve this, adjusting the height:auto property of the "site-header" ...

I encounter a CORS issue on Heroku, but strangely it only occurs after 20 minutes of deploying. Prior to that time frame, everything functions seamlessly

Today, I encountered a strange issue while hosting my first Node JS backend on Heroku. Everything runs smoothly when I register/login immediately after deploying the backend. However, if I try to register/login after about 15 minutes, I start receiving a C ...

Troubleshooting npm Err ERESOLVE peer dependencies in ReactJS for Vercel Hosting deployment

Summary After a month of work, I finally deployed my project by using Git to upload it to GitHub Repository and hosting it on Vercel. However, I encountered an error with npm code ERESOLVE which took me hours to resolve. Background Upon completing my ...

Changing the container's height in an HTML document

enter image description hereim struggling to change the height of the white dash container, and I can't quite figure out how to do it. Here is the code, any help would be appreciated: analytics.html : {% extends 'frontend/base.html' %} {% l ...

In ES5, this.method does not exist as a function

I am facing an issue with a TypeScript 2 class that targets ES5. When I run it, I receive an error in the console stating that the increment() and decrement() methods do not execute, although the switch statement works fine. class MyClass extends React. ...

Utilize CSS to format the output of a script embedded within

When I embed the following script in my HTML, the output doesn't have any styling. How can I style the script output to blend well with the existing HTML structure? I tried accessing the output by ID, but couldn't figure it out. <script> ...

What is the best way to customize column width in AG-Grid?

I am looking for a way to dynamically set column width in my table. I have provided a stackblitz example which demonstrates that when changing the screen size, only the table border adjusts, but not the column widths. Is there a way to also change the col ...

Utilizing Flask to insert data into a MySQL database table

Hey there, I'm running into some trouble with inserting values into my database. While I can successfully log in using the same method on the sign-up page, I've tried various options without success. Below is my Python code: from flask import F ...

What is causing the z-index: -1 to not function properly in this particular case?

I'm struggling to get the <i> element to display below the anchor in the stacking order. Any suggestions on how to achieve this? a.button { background-color: gray; border-radius: 5px; color: rgb(247, 247, 247); display: inline-block; ...

Tips for preventing access to user media when integrating Redux

I've been facing an issue while working with navigator.mediaDevices.getUserMedia(mediaConstraints) in conjunction with Redux. I am struggling to find a solution to stop the media stream. I attempted to halt the media stream within the reducer and act ...

Eliminate the gaps between the columns of the table

Is there a way to eliminate the gap between the day, month, and year columns in this table? <form action='goServlet' method='POST'> <table style="width:1000px" style="text-align:center"> <tr style="text-ali ...

Bulma - The Inline Imperative of Button Class

I recently started using Bulma and have been experimenting with creating a basic webpage using it. I've encountered an annoying issue where the "button is-large" class seems to be making elements on my page display inline. Below is a simple demonstr ...