I use a state to render different components in a div hence changing its height. I want my css height transition to execute when the change happens. Please someone assist me with this.
React Code:
<div className="venue-details">
{venue ?
<>
<span>Date: To Be Announced... </span><br />
<span>Location: My Location</span><br />
</>:
<>
<span>Click to view</span>
</>
}
</div>
CSS Code:
.venue-details{
position: relative;
font-size: 20px;
padding-left: 10%;
padding-bottom: 30px;
padding-right: 10%;
transition: height 1s ease-in-out;
}
2
Answers
The problem is that you’re adding/removing your spans to/from the dom, not changing the classes on them. Try something more like this:
And then your css can be more like
You could use ReactTransitionGroup to animate the height of your div element:
css: