Skip to content

Instantly share code, notes, and snippets.

@andrit
Created September 17, 2018 19:10
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 andrit/1dcae4dd1206f87630bd0777a4568d46 to your computer and use it in GitHub Desktop.
Save andrit/1dcae4dd1206f87630bd0777a4568d46 to your computer and use it in GitHub Desktop.
import React from 'react';
import Transition from 'react-transition-group/Transition';

const duration = 300;

const defaultStyle = {
  transition: `all ${duration}ms ease-in-out`,
  opacity: 0,
  top: 1000
}

const transitionStyles = {
  entering: { opacity: 0, top: 1000 },
  entered:  { opacity: 1, top: 0 },
};

export const TransitionAnimation = (Module) => {

    return class AnimateHOC extends React.Component {
        state = {in:false}

        componentDidMount() {
            this.setState({ in: true })
        }
        

        render(){
            return(
                <Transition in={this.state.in} timeout={duration}>
                    {(state) => (
                    <div style={{
                        ...defaultStyle,
                        ...transitionStyles[state]
                    }}>
                        <Module {...this.props} />
                    </div>
                    )}
                </Transition>
            )
        }
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment