0

This is my button:

<button className="inline-flex items-center justify-center w-9 h-9 border-0 outline-0 bg-transparent cursor-pointer hover:bg-vivense-gray-100 transition ease-in-out duration-300" disabled={disabledIncrementButton} onClick={increment} > 

I want to add bg-vivense-gray-100 to className according to the value "disabledIncrementButton".

For example, if disabledIncrementButton is true, then add bg-vivense-gray-100 to className;

<button **className={`inline-flex items-center justify-center w-9 h-9 border-0 outline-0 bg-transparent cursor-pointer hover:bg-vivense-gray-100 transition ease-in-out duration-300` ${disabledIncrementButton} ?? bg-vivense-gray-100}** disabled={disabledIncrementButton} onClick={increment} > 
2
  • Note that if you are using tailwind, dynamically composed classes won't be working. Commented Jun 4, 2024 at 13:46
  • @SyndRain thanks. this answer for the question you shared works. Also, given style to a component crushes on class attributes. So, i can add the following code also style={disabledDecrementButton ? { backgroundColor: "#f5f5f5" } : {}} Commented Jun 4, 2024 at 18:21

1 Answer 1

0

Conditionally applying class attributes in react

here the answer. Also,

style={disabledDecrementButton ? { backgroundColor: "#f5f5f5" } : {}} 

this works

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.