Summary
In this chapter, we learned about four methods of styling.
First, we learned that plain CSS could be used to style React apps, but all the styles in the imported CSS file are bundled regardless of whether a style is used. Also, the styles are not scoped to a specific component – we observed the container
CSS class names clashing with the App
and Alert
components.
Next, we learned about CSS modules, which allows us to write plain CSS files imported in a way that scopes styles to the component. We learned that CSS modules is an open source library pre-installed and pre-configured in projects created with Create React App. We saw how this resolved the CSS clashing problem but didn’t remove redundant styles.
Then, we discussed CSS-in-JS libraries, which allow styles to be defined directly on the React component. We used emotion’s css
prop to style the alert component without an external CSS file. The nice thing about this approach is that conditional...