question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. Itย collects links to all the places you might be looking at while hunting down a tough bug.

And, if youโ€™re still stuck at the end, weโ€™re happy to hop on a call to see how we can help out.

๐Ÿ™‹ Add styleName for React projects using css modules

See original GitHub issue

This is a ๐Ÿ™‹ feature request.

It will be really nice to have styleName feature working out-of-the-box or with minimal configuration for React projects like it is done in babel-plugin-react-css-modules which is not working with Parcel.

๐Ÿค” Expected Behavior

Code like this should work fine too:

import './App.css'

const App = () => {
    return (
        <div styleName="app">
            Hello World!
        </div>
    )
}

๐Ÿ˜ฏ Current Behavior

Only this one is working:

import styles from './App.css'

const App = () => {
    return (
        <div className={styles.app}>
            Hello World!
        </div>
    )
}

It will be a bit nicer: save typing and more React-ish.

๐Ÿ’ Possible Solution

Iโ€™m not sure here, but I think it can be done same way as in babel-plugin-react-css-modules

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:1
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

10reactions
pseldencommented, Feb 1, 2018

I was able to fix this by setting both .babelrc and .postcssrc to use the same generateScopeName:

{
  "plugins": [
    [
      "react-css-modules",
      {
        "generateScopedName": "[path]__[name]__[local]__[hash:base64:5]",
        "handleMissingStyleName": "warn"
      }
    ]
  ],
  "presets": ["env", "react"]
}
{
  "modules": true,
  "plugins": {
    "autoprefixer": {
      "grid": true
    },
    "postcss-modules": {
      "generateScopedName": "[path]__[name]__[local]__[hash:base64:5]"
    }
  }
}
1reaction
kawamurakazushicommented, May 8, 2018

Can this work using typescript?

Read more comments on GitHub >

github_iconTop Results From Across the Web

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 Style Your React App โ€“ 5 Ways to Write CSS in 2021
There is no #1 way to approach to writing styles in React for every project. Every project is different and has different needs....
Read more >
Adding a CSS Modules Stylesheet - Create React App
This project supports CSS Modules alongside regular stylesheets using the [name].module.css file naming convention. CSS Modules allows theย ...
Read more >
Using CSS modules in React - Bootcamp
If you are using create-react-app , making CSS Module for a component is ... import the css modules stylesheet as styles or [name]Styles...
Read more >
Using CSS Modules In React App - Medium
What I just showed you is how you will typically add styles to HTML elements. The browser is able to understand this two...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found