CSS in JS
“CSS in JS” refers to ideas on modularizing CSS , so it helps in maintaing large and medium scale applications easier.
React JS style
In React JS style
attribute accepts a JavaScript object with camelCased properties.
<button style={
{ color: "blue", backgroundColor: "white" }
}>Submit</button>
Webpack css-loader and style-loader
The css-loader takes a CSS file and reads all dependencies and style-loader embeds the styles into markup.
// file name : app.css
.btn {
color: white;
background-color: black;
}
import './app.css';
function () {
return (
<button className="btn">Submit</button>
);
}
CSS Modules
import styles from './app.css';
function () {
return (
<button className={styles.btn}>Submit</button>
);
}
References:
- Why I Write CSS in JavaScript
- What actually is CSS-in-JS?
- Styling and CSS
- The Differing Perspectives on CSS-in-JS
- CSS in JS
- 9 CSS in JS Libraries you should Know in 2019
- An Introduction to CSS-in-JS: Examples, Pros, and Cons
- CSS Modules
- css-loader
- style-loader
- What are CSS Modules and why do we need them?
- How to configure CSS and CSS modules in webpack
- CSS Modules
- Styling and CSS
- Adding a Stylesheet
- Block, Element, Modifying Your JavaScript Components
- Getting Started with CSS Modules
- Four ways to style react components
- Modular CSS with React