3 ms·
This strikes me as a much more sane approach, which makes me really surprised that somehow I haven't heard about it until now. To me, the biggest problem in CS
by danShumway 8y ago
This strikes me as a much more sane approach, which makes me really surprised that somehow I haven't heard about it until now.
To me, the biggest problem in CSS that makes me not completely dismissive of JS-in-CSS is scoping (although BEM does kind of tend to solve that problem pretty well for me already).
Dynamically generating the class names seems at first glance at least to be a good solution to that problem. Doing it as part of a compile step would be better than doing it clientside or serverside, but obviously that's not really feasible for most dynamic applications. Possibly there could be a Babel step that swaps out references in source code or something.
But yeah, I'm interested into looking into this more. Thanks for letting me know!
- tracker1 8y agoThere are different CSS-in-JS libraries, I'm using react-jss[1] myself, which is the example... I'm also using it configured via material-ui[2] component library which has a couple addons for nested structures, psuedo-selectors, media queries etc. I believe there are options for many of them to run a pass through your components and generate CSS at build time, but I find that dynamically loading (react-loader) my components works out better overall, and don't notice the CSS generated at runtime in practice. I do inject a default style baseline that is enough for the app loader spinner, and the global error handler's output screen. [1] https://github.com/cssinjs/react-jss https://github.com/cssinjs/react-jss [2] https://material-ui.com/ https://material-ui.com/