I would like to install css modules into create-react-app
and I came across this https://github.com/kitze/custom-react-scripts.
After setting things up, I created a test style.module.css
file in my folder and import it with import styles from './style.module.css';
like so,
import React, { Component } from 'react';
import styles from './style.module.css';
console.log(styles); //returns '/static/media/style.module.b3708639.css'
console.log(styles.red); //returns 'undefined'
export default class Form extends Component {
render = () => {
return (
<form onSubmit={this.handleSubmit}>
<TextInput />
<PasswordInput />
<Submit />
<p className={[styles.red, 'test'].join(' ')}>Test</p> //rendered <p class="test">Test</p>
</form>
);
}
handleSubmit = () => {
console.log('submit!');
}
}
This is my style.module.css content
.facebook_button { margin-top:10px; }
.red { color:red; }
Any advise?
This should be red
` – PaulProgrammer Apr 06 '18 at 04:00element should be className.
– NTP Apr 06 '18 at 08:52