Created
March 8, 2018 17:45
-
-
Save sarjumulmi/7dffd40df0262ab4b77beee864488626 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react' | |
import PropTypes from 'prop-types' | |
import {Transition} from 'semantic-ui-react' | |
export default class VanishingComponent extends Component { | |
constructor (props) { | |
super(props) | |
this.state = { | |
visible: true | |
} | |
} | |
componentDidMount () { | |
this.timer = setTimeout(() => { | |
this.setState({visible: false}) | |
}, this.props.time | |
) | |
} | |
componentWillUnmount () { | |
clearTimeout(this.timer) | |
} | |
render () { | |
const {visible} = this.state | |
return ( | |
<Transition visible={visible} animation='fade' duration={this.props.transitionDuration}> | |
{this.props.children} | |
</Transition> | |
) | |
} | |
} | |
VanishingComponent.propTypes = { | |
time: PropTypes.number, | |
transitionDuration: PropTypes.number | |
} | |
VanishingComponent.defaultProps = { | |
time: 5000, | |
transitionDuration: 500 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment