Last active
November 4, 2016 21:17
-
-
Save adambard/06047530a9bf9fec12b0ed652d46be87 to your computer and use it in GitHub Desktop.
Blink.tsx
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 * as React from 'react' | |
interface IBlinkProps { | |
period: number | |
} | |
interface IBlinkState { | |
interval: number | |
visible: boolean | |
} | |
export class Blink extends React.Component<IBlinkProps, IBlinkState> { | |
toggleVisibility(){ | |
this.setState({ | |
visible: !this.state.visible, | |
interval: this.state.interval | |
}); | |
} | |
componentWillMount(){ | |
this.setState({ | |
interval: window.setInterval( | |
this.toggleVisibility.bind(this), | |
this.props.period | |
), | |
visible: true | |
}) | |
} | |
componentWillUnmount(){ | |
window.clearInterval(this.state.interval); | |
} | |
render(){ | |
return <span style={{visibility: this.state.visible ? "visible" : "hidden"}}> | |
{this.props.children} | |
</span> | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment