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.

Use react CSS modules

See original GitHub issue

I assumed create-react-app uses react-css-modules, but this code does not work (no styles applied):

import React from 'react'
import styles from './styles.css'

const TextField = ({children}) => (
  <div className={styles.inputContainer}>
    <span className={styles.inputLabel}>{children}</span>
    <input className={styles.inputField}/>
  </div>
)

export default TextField

It does, however, work when classes are defined as strings rather than scoped to this component. I think it wouldn’t hurt to have this available for projects using create-react-app, what do you think?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

95reactions
gaearoncommented, Mar 29, 2017

Create React App does not use or support CSS Modules. You can eject and add them if you’d like.

13reactions
JawsomeJasoncommented, Apr 10, 2017

Great, recent article on using CSS Modules after ejecting Create React App: https://medium.com/nulogy/how-to-use-css-modules-with-create-react-app-9e44bec2b5c2

Read more comments on GitHub >

github_iconTop Results From Across the Web

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 >
Using CSS modules in React - Bootcamp
A CSS Module is simply a .css file, where classes act similarly to local variables in Javascript. It is a tool that makes...
Read more >
Using CSS Modules in React - OpenReplay Blog
In React js, where classes function similarly to local variables in JavaScript, a CSS Module is just a .css file. It lessens React...
Read more >
Using CSS Modules In React App - Medium
There are two different ways of using CSS Modules in a React application. When using the Create-React-App tool you are provided with a...
Read more >
How to Style React Components Using CSS Modules
How you use CSS modules in React depends on how you create the React application. If you use create-react-app, CSS modules are set...
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