4 ms·
this is incorrect. the only thing that does not work is generating the css class like: var x = 'hase-'; var t = x + 'danger' which is an antipattern. (it ca
by merb 2y ago
this is incorrect.
the only thing that does not work is generating the css class like:
var x = 'hase-';
var t = x + 'danger'
which is an antipattern. (it can even happen inside java, c#, whatever language you use and it is still an antipattern)
- phito 2y agoCan you please elaborate why it is an antipattern? I'm not sure I understand.
- sionisrecur 2y agoAt least regarding tailwindcss, it checks your code to filter out unused css classes. So it is recommended to have full class names in the code instead of constructing them by concatenating strings. So if you have a variable `buttonColor` that can be `red` or `blue` it is better to do something like switch(buttonColor) { 'red': return 'button-red'; 'blue': return 'button-blue'; } over return 'button-' + buttonColor;
- merb 2y agoif you are in a big project and want to refactor classes the string concatenation pattern gets extremely painful, it’s even worse when it’s done on the server and on the frontend. At some point you will have trouble removing your classes. My company did this a lot and know we struggle to clean it up since basically all classes are used somewhere. What we do is basically use purgecss and than diff it and look for all occurrences that got removed which will take us a few months.
- phito 2y agoOh ok it was about concatenation, not just this example case. Got it, thank you!