I’m taking a React course and currently, I’m learning how to style React Components with CSS.
The lesson mentions multiple ways to write CSS in Components (there might be more that weren’t discussed)
Vanilla JavaScript
Inline Styles
CSS Modules
Styled Components
Preprocessor (Sass)
Utility Classes (Tailwind)
CSS Framework (Bootstrap)
The instructor mentioned that the CSS method mostly depends on the project you want to build and there isn’t a best way to write CSS
I want to practice making projects as if I professional developer working for a company and write CSS the same way. I was wondering what’s the most common way that companies add CSS to their CSS Components.
I understand that different companies might have different policies on structuring code, but I want to hear your guys’ experiences while working on a company’s codebase.
In my experience, the most common approaches to styling React components in professional settings are CSS Modules, Styled Components, and CSS Preprocessors like Sass.
CSS Modules provide a way to scope CSS locally to individual components, preventing style conflicts and promoting modularity. This approach is widely used because it integrates seamlessly with the component-based architecture of React.
Styled Components offer a more JavaScript-centric approach to styling, allowing you to write CSS directly within your component files using tagged template literals. This approach can lead to more maintainable code and better component encapsulation.
CSS Preprocessors like Sass are also commonly used in professional settings due to their ability to enhance CSS with features like variables, mixins, and nesting, which can help streamline styling workflows and promote code reusability.
Ultimately, the best approach depends on the specific needs and preferences of your team and project. Some companies may prefer one method over others based on factors such as team familiarity, project requirements, and scalability. It’s essential to consider these factors and choose the approach that best fits your project’s needs while also aligning with your team’s expertise and workflow.
Check this out, becoming very popular in the industry right now:
Best thing about shadcn ui: It’s not another library you have to install.
You are setting up a basic configuration and you are ready to go. Now you can copy and paste the code you need into your projects. Uses Tailwind and is fully costumizable.