Created
January 24, 2018 17:18
-
-
Save miketahani/a5d7a122ae899d70cdb7f9d5f0c16ba7 to your computer and use it in GitHub Desktop.
React <blink>
This file contains 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' | |
class Blink extends Component { | |
constructor () { | |
super() | |
this.state = { visible: true } | |
this.blink = this.blink.bind(this) | |
this.interval = null | |
} | |
blink () { | |
this.setState( | |
prevState => ({ visible: !prevState.visible }), | |
_ => this.forceUpdate() | |
) | |
} | |
componentDidMount () { | |
this.interval = setInterval(this.blink, 500) | |
} | |
componentWillUnmount () { | |
clearInterval(this.interval) | |
} | |
render () { | |
const { visible } = this.state | |
return ( | |
<span style={{ visibility: visible ? 'visible' : 'hidden' }}> | |
{ this.props.children } | |
</span> | |
) | |
} | |
} | |
export default Blink |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment