第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何重構(gòu)那些非常相似的箭頭函數(shù)?

如何重構(gòu)那些非常相似的箭頭函數(shù)?

慕無忌1623718 2021-10-07 10:29:48
我正在重構(gòu) react 文件中的一些代碼,我有兩個函數(shù)幾乎可以做同樣的事情……但是一個返回一個函數(shù),另一個執(zhí)行一些代碼。我現(xiàn)在不太擅長 ES6 和箭頭功能。我不明白如何重構(gòu)它。 switchEventSelectedSchedule = cb => option => {    this.setState(      // Mutate the state      () => ({        eventSelected: option.id,        isLoading: true      }),      // Callback to fire when the state has been mutated with the new event id      async () => {        await this.longPollingAllMatches();        this.setState(() => ({          isLoading: false        }));        const { currentRoundId, rounds } = this.state;        cb(rounds, currentRoundId);      }    );  };  switchEventSelectedRoundTable = option => {    this.setState(      // Mutate the state      () => ({        eventSelected: option.id,        isLoading: true      }),      // Callback to fire when the state has been mutated with the new event id      async () => {        await this.longPollingAllMatches();        this.setState(() => ({          isLoading: false        }));      }    );  };在一種情況下(想象一下 if(schedule))我需要返回 cb 函數(shù),否則我必須只執(zhí)行其余的代碼。抱歉似乎很愚蠢,但我想我誤解了 ES6 語法中的某些內(nèi)容來實現(xiàn)這一目標....
查看完整描述

1 回答

?
ABOUTYOU

TA貢獻1812條經(jīng)驗 獲得超5個贊

只需switchEventSelectedRoundTable使用不執(zhí)行任何操作的回調(diào)調(diào)用另一個函數(shù)即可。由于switchEventSelectedSchedulecurried,這很簡單:

switchEventSelectedRoundTable = switchEventSelectedSchedule((rounds, currentRoundId) => {});



查看完整回答
反對 回復(fù) 2021-10-07
  • 1 回答
  • 0 關(guān)注
  • 145 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號