Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. import React from 'react';
  2.  
  3. class ProgressiveRainbowText extends React.Component {
  4. constructor(props) {
  5. super(props);
  6.  
  7. this.state = {
  8. colors: props.colors || ['red', 'orange', 'yellow', 'green', 'blue', 'violet', 'indigo'],
  9. counter: 0,
  10. unsubscribeKey: setInterval(() => this.setState({ counter: this.state.counter + 1}), 1000)
  11. }
  12. }
  13.  
  14. componentWillUnmount() {
  15. clearInterval(this.state.unsubscribeKey);
  16. }
  17.  
  18. render() {
  19. return (
  20. <p {...this.props}>
  21. {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>)}
  22. </p>
  23. );
  24. }
  25. };
  26.  
  27. export default ProgressiveRainbowText;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement