I've read that the CSS-spec does not specify case-sensitivity, which has led to some browsers treating, for example, .myheader as equal to .myHeader .
But since the standard in Javascript is to write variables in camelcase, how do I reconcile these two when using CSS-in-JS?
My React code could look like this:
import style from './style.module.css'
//...
<Button className={style.myButton} />
And the CSS would then break casing-convention:
.myButton {
background-color: blue;
}
OR my React code could look like this (which is kinda ugly):
import style from './style.module.css'
//...
<Button className={style['my-button']} />
And the CSS would then follow the kebab-case convention:
.my-button {
background-color: blue;
}
Ultimately it is up to you. If you are the only person who will be working on the project it doesn't matter. If you are working with a team, discuss with them their preference.
Personally, I've used all forms across my projects. It just depended on what looked right or felt right with the code I was working with, like in your case where you've mentioned kebab-case looks a bit ugly in amongst your React code.
Best practice would suggest kebab-case; but yeah, you don't have to, however, kebab-case may not work so well in the instance of modules/objects (className={style.like-this-example}).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With