Css Modules import not working
See original GitHub issueI am having some issues trying to get the styling to import correctly. Here’s the code:
import` React, { Component, PropTypes } from 'react';
import DatePicker from 'react-datepicker';
import moment from 'moment';
import "react-datepicker/dist/react-datepicker-cssmodules.css";
export class DateInput extends Component {
constructor(props) {
super(props);
}
state = {
startDate: moment(),
}
handleChange = (date) => {
this.setState({
startDate: date
});
}
render() {
return (
<DatePicker
selected={this.state.startDate}
onChange={this.handleChange}
/>
);
}
}
export default DateInput;
I have tried both imports (regular and cssModule) and have tried requiring both. When they render it looks like
We are using CSS modules and reduxForm, and when I inspect the page the classes seem to be present but have no styling in them. And the numbers are selectable and the calendar works as expected outside of the styling issue.
Any and all help would be appreciated
Issue Analytics
- State:
- Created 6 years ago
- Comments:9
Top Results From Across the Web
CSS modules not working for react version 16.6.0
I had this same problem and solved it by renaming my css file to: myName.module.css. and also importing like this: import styles from...
Read more >:Global + @import not working for me · Issue #294 · css- ...
I can't seem to import any css file globally... webpack config ... in https://github.com/facebookincubator/create-react-app/issues/343.
Read more >Using CSS Module Scripts to import stylesheets - web.dev
Learn how to use CSS module scripts to import CSS stylesheets using the same syntax as JavaScript modules.
Read more >How to Style React Components Using CSS Modules
CSS modules provide a way to locally scope CSS class names. You don't have to worry about overriding styles when you use the...
Read more >How to configure CSS Modules for webpack
This increase in size can lead to loads of problems, like trying to ... We need the css-loader module to interpret @import and...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Solved by placing this in my index.jsx file.
require("react-datepicker/dist/react-datepicker-cssmodules.css");
I think its not a good idea to load the css or scss file from the index. If we are using webpack. sass loader should do this. For me I just imported from scss file and it worked fine
@import "~react-datepicker/dist/react-datepicker.css";
. This should do the trick.