React Transition
React Transition
React Transition Group library is a simple implementation of animation. It does not do any animation
out of the box. Instead, it exposes the core animation related information. Every animation is basically
transition of an element from one state to another. The library exposes minimum possible state of
every element and they are given below −
Entering
Entered
Exiting
Exited
The library provides options to set CSS style for each state and animate the element based on the
style when the element moves from one state to another. The library provides in props to set the
current state of the element. If in props value is true, then it means the element is moving from
entering state to exiting state. If in props value is false, then it means the element is moving from
exiting to exited.
Installation
To install this React Transition Group library, use either of the following commands −
# npm
create a new file, HelloWorldCSSTransition.css under src/components folder and enter transition
classes.
HelloWorldCSSTransition.css
.hello-enter {
opacity: 1;
color:blue;
.hello-enter-active {
opacity: 1;
color:blueviolet;
.hello-exit {
opacity: 0;
color:red;
.hello-exit-active {
opacity: 0;
color:brown;
=======================================================================
HelloWorldCSSTransition.js
import './HelloWorldCSSTransition.css'
constructor(props) {
super(props);
this.duration = 2000;
this.state = {
inProp: true
setInterval(() => {
let newState = {
inProp: !state.inProp
};
return newState;
})
}, 3000);
render() {
return (
classNames="hello">
<div>
<h1>Hello World!</h1>
</div>
</CSSTransition>
);