A
A
Alexey Nikolaev2020-10-24 23:55:22
React
Alexey Nikolaev, 2020-10-24 23:55:22

What is the best way to name styles in css modules?

Goodnight.
In a React application I use css modules, and the question arose, how best to write class names - with a domain (component name) or without it?
- With a domain, the code is messier, but we follow the convention that component classes should be named after the component name, BEM here
- Without a domain, the code is cleaner, plus the same class names in different components (for example, item) will still be prefixed component name and hash, because css scoped modules. This suggests the meaninglessness of the component prefix in class names.

// Component.js
styles['component-name-element']
// vs
styles.element

What is better and why?
Thanks in advance.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question