79647359

Date: 2025-06-01 09:09:03
Score: 0.5
Natty:
Report link

Why doesn't the background color change with the color variable value?

Tailwind generates classnames at compile time, so you can't use arbitrary classname in runtime. This is also a very bad practicie. If you need to change background color often, you should not use a class for each of them.

Instead, use inline styling:

<div className="w-20 h-20 mx-auto mb-4" style={{backgroundColor: color}}>{color}</div>
Reasons:
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Starts with a question (0.5): Why do
Posted by: Jurakin