When writing Tailwind CSS in enterprise React or Next.js applications, two major architectural challenges arise:
In modern component-driven development, the best way to reuse Tailwind styles is React component abstraction, NOT custom CSS classes:
clsx & tailwind-merge (cn helper)When passing a custom className="px-8" to a component with default px-5, simple string concatenation yields: class="px-5 px-8". In standard CSS, the winner depends on stylesheet definition order, NOT class order in the HTML!
To resolve this reliably, the industry standard is the cn() utility (pairing clsx with tailwind-merge):
@apply Directive: When to Use (and When to Avoid)Tailwind allows bundling utilities into traditional CSS classes using @apply:
@apply recreates all the problems of traditional semantic CSS (naming fatigue, bundle bloat). In React/Vue/Svelte projects, prefer component props over @apply.${defaultClass} ${customClass}) dangerous when overriding Tailwind styles in React components?tailwind-merge in the popular cn() utility helper?@layer components { ... } directive do in Tailwind CSS?tailwind-merge to allow conditional class evaluation like isActive && "bg-blue-500"?@apply in modern component-driven frameworks like React and Next.js?Continue learning with hands-on practice, examples, and exercises in the upcoming topic.
Test your understanding of this lesson with 5 questions. Each question has one correct answer.
Practice in live mentor-led sessions with real projects, mock tests, and verifiable certification at MSK Institute.