3

i created a basic react app like this:

import React from 'react';
import style from './Button.module.scss';


export default class Button extends React.Component {
    render() {
        return (
            <button className={[style.class, 'awesome', 'great'].join(' ')}>
                hello world
            </button>
        );
    }
}

the css/scss:

.class {
    background: pink;
    color: red;


    /* not working */
    &:is(.awesome) {
        border-width: 2px;
    }

    /* not working either */
    &.awesome {
        border-width: 2px;
    }

    /* works */
    &:not(.great) {
        border-style: dotted;
    }
}

the problem: the sublass .awesome is not working, whereas .great works fine. Can you fix the code so the .awesome will work. I need some subclass of the .button, so i can toggle them at runtime.

this is the generated css on the browser, the .awesome is not generated but .great generated.

.Button_class__1tDJY:not(.Button_great__3yeAv) {
    border-style: dotted;
}
.Button_class__1tDJY {
    background: pink;
    color: red;
}

1 Answer 1

8

you should pass the classes declared at your css modules through your styles object, instead of passing a string:

      <button className={[styles.class, styles.awesome, styles.great].join(' ')}>
          hello world
      </button>
Sign up to request clarification or add additional context in comments.

1 Comment

you are welcome :) if you feel that answer your question you could consider to check as the accepted answer, cheers

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.