is a 38-class className normal or should i have extracted that six utilities ago Components
Coming from BEM, so this may just be a me problem. I have a card element whose className is 38 classes long including four responsive variants and two hover states, and it takes up three lines in the editor.
It works. It is the correct markup. I feel like I have done something wrong. Is this what everyone's code looks like or am I missing the step where you tidy it up?
@rest_day_rita · 6mo ago · 2 replies
Normal, and fine, right up until the moment you copy it.
The rule is not length, it is repetition. A 38-class element that exists once is a page, and pages are allowed to be specific. The same 12 classes in 14 files is a component you have not written yet. Extract on the second or third copy, not on first sight of a long line.
The BEM instinct is telling you that a long string is unmaintainable because in BEM a long string meant your naming had failed. Here it does not mean that - the styles are still local, still deletable, and still readable at the place they apply. What you have lost is a name, and you only need a name when something else has to refer to it.
Reply
Report
@lowell_frame · 6mo ago
prettier-plugin-tailwindcss also sorts them into a consistent order, which makes a three-line className scannable enough that you stop noticing the length. Either a genuine fix or an enabler, depending on your mood that week.
Reply
Report