Skip to content

Which bg color should be apply, when multiply bg-color class was appled to the same element? #12733

Answered by alex-krasikau
wu67 asked this question in Help
Discussion options

You must be logged in to vote

What you've written is correct. You can use different options such as if statements, the ternary operator, or clsx to choose from multiple variants of the same class. In this case, there is only one class of that kind in the resulting class name string.

To ensure predictable behavior, the resulting class string should only have one class of its kind. It can also have other classes when using modifiers.

Examples:

// correct
<div className="bg-red hover:bg-blue"...

// correct
<div className={isRed ? "bg-red" : "bg-blue"}...

// correct
<div className={clsx({ "bg-red": color === "red",  "bg-blue": color === "blue"})}...

// incorrect - because when the color is blue, it creates a conflictin…

Replies: 3 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@alex-krasikau
Comment options

Answer selected by wu67
@ArtiomEzepchick
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
4 participants