Guest User

Untitled

a guest
Mar 17th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. import React, { Component } from 'react'
  2. import PropTypes from 'prop-types'
  3. import {Transition} from 'semantic-ui-react'
  4.  
  5. export default class VanishingComponent extends Component {
  6. constructor (props) {
  7. super(props)
  8. this.state = {
  9. visible: true
  10. }
  11. }
  12.  
  13. componentDidMount () {
  14. this.timer = setTimeout(() => {
  15. this.setState({visible: false})
  16. }, this.props.time
  17. )
  18. }
  19.  
  20. componentWillUnmount () {
  21. clearTimeout(this.timer)
  22. }
  23.  
  24. render () {
  25. const {visible} = this.state
  26. return (
  27. <Transition visible={visible} animation='fade' duration={this.props.transitionDuration}>
  28. {this.props.children}
  29. </Transition>
  30. )
  31. }
  32. }
  33.  
  34. VanishingComponent.propTypes = {
  35. time: PropTypes.number,
  36. transitionDuration: PropTypes.number
  37. }
  38. VanishingComponent.defaultProps = {
  39. time: 5000,
  40. transitionDuration: 500
  41. }
Add Comment
Please, Sign In to add comment