Re:Real-world CSS vs. CSS-in-JS performance comparison
by mekkkkkk on Wednesday June 09, 2021 @10:32AM
(#27448326)
With my preferred SCSS module setup you get a hybrid solution with the best of both worlds. You can keep a clean stylesheet next to your component and then just:
import { mainGraphic } from './component.scss';
[...]
return (
<figure className={mainGraphic} />
);
Where `mainGraphic` is a regular class block in the SCSS. So it's pretty straight forward and the mapping is still fairly tight. At bundle time, the class name is minimized, deduped and a hash is added to it that corresponds to the rule content. The generated standalone CSS file also gets hashed for cache busting purposes. It's pretty neat.And since it's SCSS you can keep constants, mixins, functions, etc. imported and organized within and between SCSS files, separated from the components.
I haven't used SCSS modules though.