Install Node.js
sudo npm install create-react-app -g
yarn global add create-react-app- cd into the parent folder
- And the next command will create another folder with the name of the project
create-react-app my-app --scripts-version 1.1.5Radium is a popular package for react which allows us to use Inline Styles Javascript with Pseudo Selectors and Media Queries
yarn add radium
npm install --save radiumYou can use this on both components created with class and extends component as well as functional components. To export wrap your component inside component Radium(); See example bellow:
import Radium from 'radium';
export default Radium(my-component-name);Styled Components is a package of Es6 and CSS to style your component dynamically.
yarn add styled-components
npm install --save styled-componentsCSS modules automatically generate unique CSS class names behind when webpack compiles it.
Create-React-App supports css modules right out of the box as of version 2, which is now stable. Upgrade to v2 (react-scripts@latest) and do not need to eject.
yarn upgrade react-scripts@latest.- Run yarn eject to edit Config Folder:
webpack.config.dev.jsandwebpack.config.prod.js
yarn eject
npm run eject-
It will show Folder Config, then edit the files:
webpack.config.dev.jsandwebpack.config.prod.js -
In the file scroll down until you find this test CSA ( test: /.css$/) and add this two lines inside options
modules: true,localIdentName: '[name]__[local]__[hash:base64:5]'
File Example:
{
test: /\.css$/,
use: [
require.resolve('style-loader'),
{
loader: require.resolve('css-loader'),
options: {
importLoaders: 1,
modules: true,
localIdentName: '[name]__[local]__[hash:base64:5]'
},
},
]
}You just have to create a CSS file with the extension .module.css and add a class example .myStyle
.myStyle {
color: #fff
}import React from 'react'
import styles from 'mycssmodule.module.css'
export default () => <div className={styles.myStyle}>We are styled!</div>import classes from './App.css'; //Classes will work like a props for css, you can choose any name
<button className={classes.Button}>Text</button>