- Course on Udemy
-
https://www.udemy.com/course/react-the-complete-guide-incl-redux/
- Course source code on GitHub
-
https://github.com/academind/react-complete-guide-course-resources
6. Styling React Components
105. Module Introduction & Starting Project
The section focuses on styling React components and applications, emphasizing that it is not a CSS course but an introduction to applying CSS within React. It outlines various options for styling, starting with Vanilla CSS, and then progressing to more advanced techniques. Key topics include:
-
CSS Modules for scoping styles to specific components.
-
Styled Components, a CSS-in-JS library, exploring its benefits and drawbacks.
-
Tailwind CSS, a popular utility-first CSS framework for styling React apps.
The course will cover both static styles and dynamic, conditional styles. A starting project is provided for hands-on practice, which includes basic styling with Vanilla CSS. Participants will learn how to set up the project and see some initial styles applied, although some interactive elements like account creation and sign-in will not function yet. The next lecture will begin with applying styles using Vanilla CSS.
106. Splitting CSS Code Across Multiple Files
The text discusses styling options for React applications, particularly focusing on the use of CSS files. It explains that you can create a CSS file, such as an index.css
, to define your styles using various selectors (element, ID, class), and then import this CSS file into your JavaScript files. Using a build tool like Vite, the CSS is dynamically injected into the webpage, which can be confirmed through the developer tools.
Additionally, it emphasizes that you are not limited to a single CSS file; you can create multiple CSS files for better organization. For instance, you can separate styles related to specific components, like a header.css
for header-specific rules, and import this file in the corresponding component file (e.g., header.jsx
). After making these changes, the page will maintain the same appearance as the styles are still injected correctly by Vite, resulting in multiple style tags in the head section of the webpage.
- Splitting CSS Code
107. Styling React Apps with Vanilla CSS - Pros & Cons
The lecture discusses the use of Vanilla CSS for styling React applications. Key advantages include the ease of importing CSS files into JSX, allowing collaboration between developers and designers without interference, and the ability to write standard CSS without special conventions. This separation of concerns enables different team members to work on components and styles independently. However, there are disadvantages, such as the necessity of knowing CSS to write it effectively and the potential for styling clashes due to the lack of component scoping in Vanilla CSS. The lecturer mentions that the latter issue will be explored in more detail in the next session.