How to refactor those quite similar arrow functions? : <p>I'm refactoring some code in a react file, and I have two functions which almost does the same thing... but one return a function and the other one execute some code.</p>

<p>I'm not really good for now with ES6 and arrow function. And I don't understand how to refactor this.</p>

<pre><code> switchEventSelectedSchedule = cb =&gt; option =&gt; {
    this.setState(
      // Mutate the state
      () =&gt; ({
        eventSelected: option.id,
        isLoading: true
      }),
      // Callback to fire when the state has been mutated with the new event id
      async () =&gt; {
        await this.longPollingAllMatches();
        this.setState(() =&gt; ({
          isLoading: false
        }));
        const { currentRoundId, rounds } = this.state;
        cb(rounds, currentRoundId);
      }
    );
  };

  switchEventSelectedRoundTable = option =&gt; {
    this.setState(
      // Mutate the state
      () =&gt; ({
        eventSelected: option.id,
        isLoading: true
      }),
      // Callback to fire when the state has been mutated with the new event id
      async () =&gt; {
        await this.longPollingAllMatches();
        this.setState(() =&gt; ({
          isLoading: false
        }));
      }
    );
  };
</code></pre>

<p>in one case (imagine if(schedule)) I need to return the cb function else I must just execute the rest of the code.</p>

<p>Sorry seems dumb but I think I misunderstood something in the ES6 syntax to achieve this....</p>

<p>Many thx !</p>
