How it works…

Let's create and style a basic component, a colored button, trying to take advantage of as many SASS features as possible. This will be an extreme example, because it's not very likely you'll have such a complex way of creating simple code, but we want to highlight SASS here.

First, the code for the button itself, which we will call SassButton. It has three props: normal (if true, will show normal colors; if false, alert ones); buttonText, which will be displayed by the button; and onSelect, a callback for clicks. I highlighted the CSS-related lines in the following code snippet:

// Source file: /src/components/sassButton/sassButton.js/* @flow */import React from "react";import PropTypes from "prop-types";import "./styles.css"; ...

Get Modern JavaScript Web Development Cookbook 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.