Created
June 7, 2019 17:13
-
-
Save Ratstail91/20abe3a8f52a6598e474b86ffc3cd265 to your computer and use it in GitHub Desktop.
Party Time!
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 from 'react'; | |
class ProgressiveRainbowText extends React.Component { | |
constructor(props) { | |
super(props); | |
this.state = { | |
colors: props.colors || ['red', 'orange', 'yellow', 'green', 'blue', 'violet', 'indigo'], | |
counter: 0, | |
unsubscribeKey: setInterval(() => this.setState({ counter: this.state.counter + 1}), 1000) | |
} | |
} | |
componentWillUnmount() { | |
clearInterval(this.state.unsubscribeKey); | |
} | |
render() { | |
return ( | |
<p {...this.props}> | |
{Object.keys(this.props.children).map((key) => <span key={key} style={{ color: this.state.colors[(key + this.state.counter) % this.state.colors.length] }}>{this.props.children[key]}</span>)} | |
</p> | |
); | |
} | |
}; | |
export default ProgressiveRainbowText; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment