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

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

在使用ES6類時(shí),“超級(jí)()”和“超級(jí)(道具)”有什么區(qū)別?

在使用ES6類時(shí),“超級(jí)()”和“超級(jí)(道具)”有什么區(qū)別?

慕田峪4524236 2019-07-05 18:37:07
在使用ES6類時(shí),“超級(jí)()”和“超級(jí)(道具)”有什么區(qū)別?什么時(shí)候通過(guò)?props到super()為什么?class MyComponent extends React.Component {   constructor(props) {     super(); // or super(props) ?   }}
查看完整描述

3 回答

?
慕碼人8056858

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

當(dāng)一個(gè)人需要通過(guò)時(shí),只有一個(gè)原因。propssuper():

當(dāng)你想要訪問(wèn)this.props在構(gòu)造函數(shù)中。

經(jīng)過(guò):

class MyComponent extends React.Component {    
    constructor(props) {
        super(props)

        console.log(this.props)
        // -> { icon: 'home', … }
    }}

未通過(guò):

class MyComponent extends React.Component {    
    constructor(props) {
        super()

        console.log(this.props)
        // -> undefined

        // Props parameter is still available
        console.log(props)
        // -> { icon: 'home', … }
    }

    render() {
        // No difference outside constructor
        console.log(this.props)
        // -> { icon: 'home', … }
    }}

請(qǐng)注意,經(jīng)過(guò)或不通過(guò)propssuper無(wú)效關(guān)于以后使用this.propsconstructor..那是rendershouldComponentUpdate,或事件處理程序能接觸到它。

這在索菲·阿爾伯特的書(shū)中有明確的說(shuō)法回答一個(gè)類似的問(wèn)題。


文件-狀態(tài)和生命周期,將本地狀態(tài)添加到類中,點(diǎn)2-建議:

類組件應(yīng)該始終使用props.

但是,沒(méi)有提供任何理由。我們可以推測(cè),這要么是子類的原因,要么是為了將來(lái)的兼容性。


查看完整回答
反對(duì) 回復(fù) 2019-07-05
  • 3 回答
  • 0 關(guān)注
  • 575 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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