question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using props does not work

See original GitHub issue

Given the following code

const TimelineCurrent = tw.div<{ position: number }>`
  absolute
  left-0
  top-[0.575rem]
  ${(p) => `w-[calc(${p.position}%-0.75rem)]`}
  h-[0.35rem]
`;

it renders the following HTML

<div position="100" class="absolute left-0 top-[0.575rem] w-[calc(100%-0.75rem)] h-[0.35rem]"></div>

But the w-[calc(100%-0.75rem)] part is not picked up by Tailwind JIT, so it has no effect. Am I doing something wrong here?

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
mauriceackelcommented, Apr 10, 2022

JIT runs at build time, but your class name gets computed at runtime… Hence, tailwind does not know the actual name of the class at build time and cannot generate the CSS for it.

0reactions
alexjidrascommented, May 4, 2022

@azzlack that’s not an issue. You wrote the calc css syntax wrong. calc(100%-0.75rem) will not work even with css. You should add a space around the - operator. Like this calc(100% - 0.75rem). With tailwind spaces inside custom classes should be marked with _ so your final class should be w-[calc(100%_-_0.75rem)].

Read more comments on GitHub >

github_iconTop Results From Across the Web

React: Passing Props not working. What am I missing?
All you have to do is change up how you set it up on App. Props need to be passed on the tag,...
Read more >
How passing props to component works in React
Master how to pass props (properties) to components in React with this useful beginner's guide, including demo code.
Read more >
passing children via props does not work properly on React ...
The way to pass children in a .astro file is via the content, not props. Once you're in a React component you pass...
Read more >
How to use Props in React - Robin Wieruch
Everything you need to know about props in React. How to pass props to components, how to set default props, how to know...
Read more >
How to Use Props in React - freeCodeCamp
In this tutorial, we'll talk about an important concept in React – props. I'll show you how to use them to keep the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found