react-spinjs icon indicating copy to clipboard operation
react-spinjs copied to clipboard

update spinner when props change

Open aymericbouzy opened this issue 9 years ago • 2 comments

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

aymericbouzy avatar Dec 08 '16 15:12 aymericbouzy

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 avatar Dec 08 '16 16:12 aymericbouzy

#6

aymericbouzy avatar Dec 08 '16 16:12 aymericbouzy