4

I'm new to CSS Modules and React.

import React, { useState } from "react"
import styles from "./Counter.module.css"

function Counter() {
    const [count, setCount] = useState(0)

    const increase = () => {
        setCount(count + 1)
    }

    const decrease = () => {
        setCount(count - 1)
    }
    return (
        <div>
            <h2>This is a counter</h2>
            <p>Current number: {count}</p>
            <button className={styles.button__increase} onClick={increase}>+++</button>
            <button className={styles.button__decrease} onClick={decrease}>---</button>
        </div>
    )
}

export default Counter

I added the class {styles.button__decrease}. How can I now add another class to this className when using CSS Moduls? I have the class ".button" and ".button--decrease" in my CSS-file but I'm not sure how to apply more than one.

Thank you in advance!

3 Answers 3

8

className={`${styles.button} ${styles.button__decrease}`} should do the job!

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

1 Comment

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
3

You can using package name classnames

import classNames from 'classnames'
<button className={classNames(style.button, style.button__decrease)} />

or manually

<button className={[style.button, style.button__decrease].join(' ')} />

// or
function classnames(...classes) {
  return classes.join(' ')
}
<button className={classnames(style.button, style.button__decrease)} />

Comments

0
className={`${Styles.inputData} ${"SubSection"}`} 

using this simple formate should work

Comments

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.