Skip to content

Instantly share code, notes, and snippets.

@sarjumulmi
Created March 8, 2018 17:45
Show Gist options
  • Save sarjumulmi/7dffd40df0262ab4b77beee864488626 to your computer and use it in GitHub Desktop.
Save sarjumulmi/7dffd40df0262ab4b77beee864488626 to your computer and use it in GitHub Desktop.
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