Skip to content

Conversation

@aymericbouzy
Copy link

I haven't tested this code, but it should work.

@aymericbouzy
Copy link
Author

aymericbouzy commented Dec 8, 2016

Here is a Test component:

class Test extends Component {
  constructor(props) {
    super(props);
    this.state = {
      red: false,
    };
    this.toggleColor = this.toggleColor.bind(this);
  }

  toggleColor() {
    if (this._mount) {
      this.setState({red: !this.state.red});
      setTimeout(this.toggleColor, 1000);
    }
  }

  componentDidMount() {
    this._mount = true;
    this.toggleColor();
  }

  componentWillUnmount() {
    this._mount = false;
  }

  render() {
    return (
      <ReactSpinner color={this.state.red ? 'red' : 'blue'} />
    );
  }
}

Once again, not tested, but should work.

@aymericbouzy
Copy link
Author

#6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant