1

I'm styling my react app. I'm using css-modules with webpack. Here's my config:

{ test: /\.css$/, loaders: ["style", "css?modules"] },

I styled my component, made a coffee and now it's not working. So I've got a stylesheet I want to use. I'm importing it with:

import styles from "./search.css";

But, when I break inside my component, styles is not defined. None of my styles are now being applied. Here's an example of how I'm using it:

// the chrome inspector only shows the first two styles, the last is not there
<div className={["col-md-2", "col-lg-1", styles.startTimes]}>

Why would styles be empty?

1 Answer 1

2

Finally worked it out. This is not the right syntax:

<div className={["col-md-2", "col-lg-1", styles.startTimes]}>

You have you use classNames and instead do:

<div className={cx("col-md-2", "col-lg-1", styles.startTimes)}>

You also need to only use class names in your CSS. If you style tag names directly (h1, etc) these are not applied locally.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.