Styling components with CSS modules
CSS modules are a mechanism for scoping CSS class names. The scoping happens as a build step rather than in the browser. In fact, CSS modules are already available in our app because Create React App has configured them in webpack.
We are going to update the styles on the Header and App components to CSS modules in the following steps:
- Rename
Header.csstoHeader.module.cssandApp.csstoApp.module.css. Create React App is configured to treat files ending withmodule.cssas CSS modules. - Open
App.tsxand change theApp.cssimportstatement to the following:import styles from './App.module.css'
- Update the
classNameprop on thedivelement to the following:<div className={styles.container}>This references the container class with the
AppCSS module. - Open
Header.tsxand change theHeader.cssimportstatement to the following:import styles from './Header.module.css'
- Update the
classNameprop on the...