Skip to content

Instantly share code, notes, and snippets.

@Ratstail91
Created June 7, 2019 17:13
Show Gist options
  • Save Ratstail91/20abe3a8f52a6598e474b86ffc3cd265 to your computer and use it in GitHub Desktop.
Save Ratstail91/20abe3a8f52a6598e474b86ffc3cd265 to your computer and use it in GitHub Desktop.
Party Time!
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