score:2

Accepted answer
  constructor() {
    super();
    this.state = {
       favourite: 0
    }

    this.favChosen = _.debounce(this.favChosenRaw, 1000);     
  }

  handleClick() {
    this.setState((prevState) => ({
       favourite: (prevState.favourite + 1) % 3
    }));

    this.favChosen()

  }
  favChosenRaw(){....

score:1

class Switch extends React.Component {
  constructor() {
    super();
    this.state = {
       favourite: 0
    }
  }

  handleClick() {
    this.setState((prevState) => ({
       favourite: (prevState.favourite + 1) % 3
    }), () => {this.favChosen()});

  }
  favChosen(){
    if (this.state.favourite === 0) {
    return this.testConsole1();
  } else if (this.state.favourite === 1) {
    return this.testConsole2();
  } else if (this.state.favourite === 2) {
    return this.testConsole3();
  }
 testConsole1() {
    console.log('This will be a fetch 1')
  }
  testConsole2() {
    console.log('This will be a fetch 2')
  }
  testConsole3() {
    console.log('This will be a fetch 3')
  }
  render () {
    const { favourite } = this.state;
    const fill = favourite === 0 ? "grey" :
                 favourite === 1 ? "green" : "red";
    return (
        <button className="favStar" onClick={this.handleClick.bind(this)} >
      <svg width="100" height="100">
        <g>
          <path id="svg_2" d="m0,38l37,0l11,-38l11,38l37,0l-30,23l11,38l-30,-23l-30,23l11,-38l-30,-23l0,0z" stroke-linecap="null" stroke-linejoin="null" stroke-dasharray="null" stroke-width="0" fill={fill} />
        </g>
      </svg>
            </button>
    );
  }
}

React.render( <Switch />, document.getElementById( "page" ) );

Related Query

More Query from same tag