Repository navigation
Please enlighten me🙏 #14987
Replies: 2 comments
|
I would start with plain Tailwind utility classes rather than adding a styled-components abstraction immediately. The main advantage of Tailwind is that styling is visible alongside the component's markup. Introducing another abstraction can make that relationship harder to follow without necessarily reducing complexity. A practical approach: 1. Use utilities directly for small components. <button
className="rounded-md bg-blue-600 px-4 py-2 text-white hover:bg-blue-700"
>
Save
</button>2. Extract reusable React components when markup and behavior repeat. For example, a shared 3. Use variants for genuine component-level differences. Libraries such as 4. Use This helps avoid conflicting utilities, provided the merge configuration understands your custom utilities. 5. Keep design tokens centralized. Colors, typography, spacing, and themes should follow a shared design system instead of arbitrary values scattered throughout components. My rule of thumb:
I wouldn't introduce The simplest abstraction is usually the one you don't need to create. |
|
Thank you so much for the detailed and thoughtful response!
I often found myself using a regular CSS file alongside Tailwind
whenever styling got too complex, but I was always second-guessing
myself and wondering if that was an anti-pattern. Seeing your rule of
thumb ("Complex styling that utilities don't express clearly: regular
CSS") really reassured me that it is a completely valid and practical
approach.
This was exactly the clarity I needed. Really appreciate your help!
|
Uh oh!
There was an error while loading. Please reload this page.
What's the smartest and cleanest way to use Tailwind CSS?
Should we use the tailwind-styled-components library to write styled-components-like code?
Or should we just add multiple class names inline like traditional CSS classes?
What's your preferred approach to using Tailwind CSS?
All reactions