Locally scoped CSS

Now, it is time to create our app, which will consist of a Simple button, of the same sort we used in previous examples. We will use it to show all the features of the CSS modules.

Let's create an index.js file, which is the entry we specified in the webpack configuration, and let's import React and ReactDOM as well:

  import React from 'react';  import { render } from 'react-dom';

We can then create a Simple button. As usual, we are going to start with a nonstyled button, and we will add the styles step by step:

  const Button = () => <button>Click me!</button>;

Finally, we can render the button into the DOM:

  render(<Button />, document.body);

Please note that rendering a React component into the body is bad practice, but ...

Get React Design Patterns and Best Practices - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.