Performance: Tailwind with React components
MEDIUM IMPACT
This affects how fast the page loads and how quickly React components render with Tailwind styles applied.
const buttonClasses = "text-white bg-blue-500 hover:bg-blue-700 font-bold py-2 px-4 rounded";
function Button() {
return <button className={buttonClasses}>Click me</button>;
}function Button() {
return <button className="text-white bg-blue-500 hover:bg-blue-700 font-bold py-2 px-4 rounded">Click me</button>;
}| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Inline long Tailwind classes in JSX | Normal | Multiple on prop changes | Medium | [X] Bad |
| Reused Tailwind class strings | Normal | Single or minimal | Low | [OK] Good |
| Conditional inline class strings | Normal | Multiple on each render | Medium | [X] Bad |
| Separated static and dynamic classes | Normal | Minimal | Low | [OK] Good |