I'm trying to change a class name dynamically in react.
I am importing the classes from a related css file like this:
import classes from "./Board.module.css";
And in my Board component, I want to return a classname based on something I generate.
It can be "card" "card activate " "card disable", and I have 3 classes in my css file
.card {
do card something
}
.card.activate {
do card activate something
}
.card.disable {
do card disable something
}
How can I do it because concatenating doesn't seem to be working
Edit: I am trying to to this:
import "./Board.module.css"
const Card = (props) => {
const itemClass =
"card" + (props.item.stat ? " active " + props.item.stat : "");
return (
<div className={itemClass} onClick={() => props.clickHandler(props.id)}>
<label>{props.item.content}</label>
</div>
);
};
export default Card;
and the CSS is :
.card.wrong{
background-color: red;
}
.card.correct{
background-color: green;
}
.card.active{
transform: rotateY(0);
}
I am doing so that every time I click a card, I change its class name to active and something and based on that I do a color but the class is undefined so I don't know what to do