I have a component that has dynamic class names based on the state of the component. The initial state of the menu component is false
so an exit animation triggers when I load the site. I'm trying to not play the exit animation on initial render, I'm trying to trigger the animation only when the user clicks away from the menu.
@keyframes menuEnter {
from {
transform: translateY(-100vh);
}
to {
transform: translateY(0);
}
}
@keyframes menuExit {
from {
transform: translateY(0);
}
to {
transform: translateY(-100vh);
}
}
const [showMenu, setShowMenu] = useState(false)
<div className={`menuContainer ${showMenu ? `menuEnter` : 'menuExit'}`} id='menu'>
I'm trying to bail out of the exit animation because it doesn't make sense to play the exit animation on initial render.
The state changes onClick, when state is true
onClick sets it to false
and when state is false
the onClick sets it to true
.
menuExit
only if your menu is opened. And also add the classes on an event triggered by your menu trigger ( hover, click whatever ) – Girosol