Skip to content

How to use conditional styles? #54

Answered by kavinvalli
60pfennig asked this question in Q&A
Discussion options

You must be logged in to vote

It just works like any other variable inside a template literal.

const className = `${tw.some_common_class} ${active ? tw.class_you_want : tw.some_other_class}`

That being said, I recommend using the clsx and tailwind-merge packages to work with conditional classes

ps: I wrote this answer on my phone so please ignore any typos/syntax errors

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@60pfennig
Comment options

Answer selected by 60pfennig
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants