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

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

ES6 函數(shù)式組件 React.js 中的 Getter

ES6 函數(shù)式組件 React.js 中的 Getter

倚天杖 2021-08-26 17:44:13
我在 React 中使用無狀態(tài)組件,我發(fā)現(xiàn)使用 Getters 有問題。對于有狀態(tài)組件(基于類的組件),它可以正常工作,但是如何在無狀態(tài)(功能組件)中使用它; // this is code for statefull component(class based component)get lookupsOfSelectedGroup(){        const lookUps = this.props.mainLookups.filter(          item => item.extras.parent === this.state.activeGroup        );        if (lookUps[0] && lookUps[0].responseStatus === 200) {          return lookUps[0].response.lookup;        }        return [];  }// this is the code for functional component I did:    get lookupsOfSelectedGroup =()=> {        const lookUps = this.props.mainLookups.filter(          item => item.extras.parent === this.state.activeGroup        );        if (lookUps[0] && lookUps[0].responseStatus === 200) {          return lookUps[0].response.lookup;        }        return [];      }    ```Cannot find name 'get'.
查看完整描述

2 回答

?
慕村9548890

TA貢獻(xiàn)1884條經(jīng)驗(yàn) 獲得超4個(gè)贊

您只能在 ES6 類和對象字面量中使用getset關(guān)鍵字。



查看完整回答
反對 回復(fù) 2021-08-26
?
蠱毒傳說

TA貢獻(xiàn)1895條經(jīng)驗(yàn) 獲得超3個(gè)贊

getter 只能定義為對象或類的屬性。您不能直接在函數(shù)體中定義它們。

您要么需要lookupsOfSelectedGroup用普通函數(shù)替換(可能是更好的解決方案),要么將其包裝在對象文字中。


查看完整回答
反對 回復(fù) 2021-08-26
  • 2 回答
  • 0 關(guān)注
  • 304 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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