Naming Conventions for React Styling
Sources:
- **
Overview
TIP
It’s a good idea to use a consistent naming convention for your CSS classes to keep your styles organized and easy to understand. Some popular conventions include Block-Element-Modifier (BEM) and Scalable and Modular Architecture for CSS (SMACSS).
Examples
Here’s an example of how these conventions might be used together in a React component:
And the corresponding CSS:
In this code, the following naming conventions are used:
- The React functional component is named
ProfileInfo
, which follows theUpperCamelCase
orPascalCase
convention for naming React components. - The CSS file imported is named
ProfileInfo.css
, which also follows theUpperCamelCase
convention and matches the name of the component. - The class in the JSX template is
profile-info
, which follows the lowercase and hyphen-separated convention, also known askebab-case
, for naming CSS classes.
You can read more about naming conventions here if you like.
Appendix
Note created on 2024-05-13 and last modified on 2024-05-13.
See Also
Backlinks
(c) No Clocks, LLC | 2024