I know that using ReactCSSTransitionGroup
you can apply it to a list of items and have then animate as they appear or disappear. What about a single component though?
See JSFiddle here, where I've got a CSS animation when the item appears. But I don't know if there's a way to make it animate upon being hidden.
https://jsfiddle.net/eq263rk2/
We do this (same with animation): import Animated from "react-mount-animation"; const MyComponent = () => { const [isMounted, setIsMounted] = useState(false); ... return ( <Animated. div //You can use any HTML element here show={isMounted} mountAnim={` 0% {opacity: 0} 100% {opacity: 1} `} > Hi World!
You need to give . App a height of 100% and your #root div that renders your entire React App needs a set height. You also need to change the transition from using height to using max-height .
Hence, props can also be used to hide or show a component. For example, if we pass props, based on the props value, we can hide or show the elements, just like in the below example. Here in this example, the props we have declared is called showHideDemo1 along with the state value.
Sure! Just use the enter
and leave
variants (though you should always render the TransitionGroup
component):
var TheThing = React.createClass({
render() {
var component;
if (this.props.visible) {
component = <div className="the-thing">The Thing</div>;
}
return (
<ReactCSSTransitionGroup transitionName="thing">
{component}
</ReactCSSTransitionGroup>
)
}
});
and
.thing-enter {
opacity: 0.01;
transition: opacity 1s ease-in;
}
.thing-enter.thing-enter-active {
opacity: 1;
}
.thing-leave {
opacity: 1;
transition: opacity 1s ease-in;
}
.thing-leave.thing-leave-active {
opacity: 0.01;
}
Example: https://jsfiddle.net/BinaryMuse/3fkso0kq/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With