Home

Awesome

React Easy Transition

npm install react-easy-transition --save

Easy transitions in react and react-router

Usage

For a simple fade-out fade-in effect on route change with react-router :

import EasyTransition from 'react-easy-transition'

<EasyTransition
    path={location.pathname}
    initialStyle={{opacity: 0}}
    transition="opacity 0.3s ease-in"
    finalStyle={{opacity: 1}}
>
    {this.props.children}
</EasyTransition>

Multiple transitions on different properties:

<EasyTransition
    path={location.pathname}
    initialStyle={{opacity: 0, color: 'red'}}
    transition="opacity 0.3s ease-in, color 0.5s ease-in"
    finalStyle={{opacity: 1, color: 'green'}}
>
    {this.props.children}
</EasyTransition>

Optionally set a leaveStyle if it is different than the initialStyle:

<EasyTransition
    path={location.pathname}
    initialStyle={{opacity: 0, color: 'red'}}
    transition="opacity 0.3s ease-in, color 0.5s ease-in"
    finalStyle={{opacity: 1, color: 'green'}}
    leaveStyle={{opacity: 0, color: 'gray'}}
>
    {this.props.children}
</EasyTransition>

You can set a custom component or classname if needed

<EasyTransition
    path={location.pathname}
    initialStyle={{opacity: 0, color: 'red'}}
    transition="opacity 0.3s ease-in, color 0.5s ease-in"
    finalStyle={{opacity: 1, color: 'green'}}
    component="MyCustomReactComponent"
    className="myCustomCSSClass"
>
    {this.props.children}
</EasyTransition>

NOTE: If your <Link> component (or any children of this) contains styling/classes that use transition, make sure not to use transition: all as this will prevent react-easy-transition from fading out.

Live Demo

Live Demo here

Features

This module solves the following issues:

Example