Skip to content

Instantly share code, notes, and snippets.

@shivekkhurana
Forked from mhaagens/gist:61f88e3fbfddbe2c00708f3ebd099be4
Last active January 2, 2018 18:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shivekkhurana/8126b4cf4c7b8dbaa18612ca4c3091fa to your computer and use it in GitHub Desktop.
Save shivekkhurana/8126b4cf4c7b8dbaa18612ca4c3091fa to your computer and use it in GitHub Desktop.
Transition Motion React Router 4 Route Transition
import React from 'react';
import {Route} from 'react-router-dom';
import PropTypes from 'prop-types';
import {TransitionMotion, spring} from 'react-motion';
const FadeRoute = ({component: Component, ...rest }) => {
return (<Route {...rest} children={({location, match}) => (
<TransitionMotion
willEnter={() => ({opacity: 0})}
willLeave={() => ({opacity: spring(0)})}
styles={match ? [{
key: location.pathname,
style: {opacity: spring(1)},
data: {match, location}
}] : []}
>
{interpolatedStyles => (
<div className="route">
{interpolatedStyles.map(({key, style, data}) => (
<div
className="page"
key={key}
style={style}
>
<Component {...data} />
</div>
))}
</div>
)}
</TransitionMotion>
)} />);
};
FadeRoute.propTypes = {
component: PropTypes.node
};
export default FadeRoute;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment