React
  • Introduction
  • Getting Started
    • Introduction
    • Before you get started
  • 1. Fundamentals
    • Introduction
    • Rendering
      • JSX
      • Exercise
      • Solution
    • Components
      • Stateless
        • Exercise
        • Solution
      • Stateful
        • Exercise
        • Solution
      • Styling
        • Exercise
        • Solution
        • Using CSS Modules
    • Folder Architecture
  • 2. Intermediate
    • Lifecycle methods
    • Controlled and Uncontrolled components
    • Anti-patterns
    • Refs and the DOM
    • Lifting State Up
  • 3. Advanced Topics
    • Conventions
    • Reconciliation
    • Performance Optimizations
      • Avoiding Reconciliation
      • PureComponent
      • Avoiding inline lambdas
      • Development vs Production build
    • Context
  • 4. Advanced Patterns
    • Higher-order Components
    • Children as Function
    • Renderless Components
    • Portals
    • Error handling
  • Exercises
    • Introduction
    • 1. ProductList light
      • Step 1
      • Step 2
      • Step 3
      • Step 4
      • Extra
      • Solution
Powered by GitBook
On this page
  1. Exercises
  2. 1. ProductList light

Step 3

Now that you have your components ready, let's add some style to them. Create a CSS file for each of your components and import them by doing:

/* Title.css */
.Title {
  font-size: 24px;
}

/* ProductList.css */
.ProductList {
  background: white;
}
// Title.js
import './Title.css'

render() {
  return (
    <div className="Title">
      ...
    </div>
  )
}

// ProductList.js
import './ProductList.css'

render() {
  return (
    <table className="ProductList">
      ...
    </table>
  )
}

⚠️ Like for importing JSON, importing a CSS file is made possible because you are using create-react-app. Under the hood, create-react-app has a webpack configuration that allows you to import CSS files.

If you inspect the source of your app, you will see that the CSS is inlined in the page. ⚠️ You are using plain CSS here, it is not CSS modules, so if you use same class names, you will have collision.

PreviousStep 2NextStep 4

Last updated 6 years ago