CSS Modules
See original GitHub issueI had these lines at the top of my file:
import Select from 'react-select';
import 'react-select/dist/react-select.css';
but the select was showing up un-styled. I made a subtle change in my webpack config file by changing this line:
{test: /\.css$/, loader: 'style!css?modules!postcss'}
to this:
{test: /\.css$/, loader: 'style!css!postcss'}
and now it works.
Does that mean I cannot use css modules with React-Select?
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:21
Top Results From Across the Web
Documentation about css-modules - GitHub
A CSS Module is a CSS file in which all class names and animation names are scoped locally by default. All URLs (...
Read more >What are CSS Modules and why do we need them?
According to the repo, CSS modules are: CSS files in which all class names and animation names are scoped locally by default. So...
Read more >Component-Scoped Styles with CSS Modules - Gatsby
A CSS Module is a CSS file in which all class names and animation names are scoped locally by default. CSS Modules let...
Read more >Adding a CSS Modules Stylesheet - Create React App
CSS Modules let you use the same CSS class name in different files without worrying about naming clashes. Learn more about CSS Modules...
Read more >A deep dive into CSS Module - LogRocket Blog
According to the official CSS Module GitHub repository, a CSS Module is a CSS file in which all class names and animation names...
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 FreeTop 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
Top GitHub Comments
Does this all still apply with react-select v2 and above?
Specifically what is painfully missing from the react-select docs is an example that uses custom styles with CSS Modules. The docs claim that CSS Modules are supported: https://react-select.com/styles#using-classnames but that does not seem to be the case, because a prefix is simply not good enough for CSS Modules: the class names are compiled into something different for use at run time. I am able to get around this by using the
:global
keyword in my stylesheet, but this is circumventing CSS Modules, not using them! Is this the approved way to set custom styles?Please update the docs to provide an example using CSS Modules and
react-select
. Thanks.Hello guys,
I solved this problem by importing the react-select css like this in my js:
import '!style-loader!css-loader!react-select/dist/react-select.css';
You need to add the
-loader
part if you are usingwebpack@2.4.1
or above.I found this solution here.