I have this down arrow image, which rotates to an up arrow when the boolean "open" function switches, with a transition effect.
<img src="./downArrow.png" className={`${(open) && "rotate-180 transition-all"}`} />
But when I try to close the container, the arrow goes back to its original state without the transition effect. I tried already a few different ways to apply this effect to (!open) as well but none worked.
How can I do this?
2
Answers
In your code, the
transition-all
class also gets removed whenopen
is false.To avoid this, move
transition-all
out of the condition:This way,
transition-all
is always present in the class string even whenopen
is false.I think there are two problems in your code.
1-The image was not imported properly.
2-There is no transition from 180-0.
or