DEV Community

Discussion on: How to Create Modern Cards using React and Tailwind

Collapse
 
shaglock profile image
Ilya Shaplyko • Edited

Is there any reason why you moved the styles to separate CSS file with @apply instead of writing them directly in JSX?

Collapse
 
femil profile image
Femil Savaliya

because you can use one @apply style in multiple time in project :)

Collapse
 
franciscomendes10866 profile image
Francisco Mendes

It was simply because this way it's easier to read the code so I can do the coditional rendering properly and so I can make changes faster. It's just the approach I like to take when I work on styling components, in my view it's simpler and more intuitive to separate the contexts. 😊

Collapse
 
optimbro profile image
Rahul

I like this approach as well. So, when we use JIT mode, it still purges unused styles, and we have the same output as we were directly using utility classes in JSX right?

Thread Thread
 
j471n profile image
Jatin Sharma

The answer is No, By default, Tailwind only removes unused classes that it generates itself, or has been explicitly wrapped in a @layer directive. It will not remove unused styles from third-party CSS.

Thread Thread
 
franciscomendes10866 profile image
Francisco Mendes

It's correct 💪

Collapse
 
pra3t0r5 profile image
Pra3t0r5

I highly recommend not placing any styles inside JSX, instead, write a styles constant in the same file, and outside the components return function.

That way react performs way better, since inline styles are reprocessed with every state change.

Outside-return and imported styles do not suffer from this performance impact.

Collapse
 
shaglock profile image
Ilya Shaplyko

sorry, what I meant is not inline styles, but Tailwind classes.

Some comments have been hidden by the post's author - find out more