I have a variable that I would like to use to define a class with TailwindCSS:
const frac = // some integer between 0 and 12
With this variable this class definition works as intended:
className={
(frac === 0 ? "w-0" : "") +
(frac === 1 ? "w-1/12" : "") +
(frac === 2 ? "w-2/12" : "") +
(frac === 3 ? "w-3/12" : "") +
(frac === 4 ? "w-4/12" : "") +
(frac === 5 ? "w-5/12" : "") +
(frac === 6 ? "w-6/12" : "") +
(frac === 7 ? "w-7/12" : "") +
(frac === 8 ? "w-8/12" : "") +
(frac === 9 ? "w-9/12" : "") +
(frac === 10 ? "w-10/12" : "") +
(frac === 11 ? "w-11/12" : "")
}
But this does not:
className={"w-" + String(frac) + "/12"}
Where things get wierd is that if I first use the working example, then switch to the example that doesn't work without stopping the program (locally rerunning "npm start"), the second example works. Obviously I would like to use the concise option, but it seems to only work after each option has been manually rendered. I've also tried to render just one of the options, and after switching to the nonworking example, it will render just that one option and not the others.