How would I write and call this CSS in React CSS Modules?
.is-invalid ~ .validationError {
display: inline !important;
}
Calling styles.validationError
does not work.
How would I write and call this CSS in React CSS Modules?
.is-invalid ~ .validationError {
display: inline !important;
}
Calling styles.validationError
does not work.
3
Answers
I was able to fix this by using global.
I can now call ${syles.validationError} and it works.
You are referring to babel-plugin-react-css-modules in the question tags, but don’t provide any further context how you use it. This makes it hard to understand your exact problem, but I’ll give it a shot anyway.
I assume you are trying to import a CSS file as a module like this:
Your CSS will generate two locally scoped classes when imported as a CSS module. The code above works as expected when you use regular CSS modules, for example via a Webpack loader.
However, the Babel plugin that you use actually expects a different way of adding styles. Here is what you should do according to the documentation:
babel-plugin-react-css-modules
will load the CSS at compile time and replace thestyleName
attributes with the scopedclassName
s inline. The docs linked above explain this in further detail.