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

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

無法獲取未定義的值,用戶的顯示名稱。我已經(jīng)使用 props 來使用此文件中的用戶狀態(tài)

無法獲取未定義的值,用戶的顯示名稱。我已經(jīng)使用 props 來使用此文件中的用戶狀態(tài)

慕慕森 2021-11-12 14:54:01
我無法顯示用戶數(shù)據(jù),例如name他登錄時的數(shù)據(jù)。我使用過props和stateuser ascurrentUser但我無法訪問這些字段,因為錯誤說它無法讀取未定義的屬性。class UserPanel extends React.Component {    state = { user: this.props.currentUser }    dropdownOptions = () => [        {            key: "user",            text: (                <span>                    Sign in as <strong>{this.state.user.displayName}</strong>                </span>            ),            disabled: true        },        {            key: "avatar",            text: <span>Change Avatar</span>        },        {            key: "signout",            // Set a signout Function to enable user to sign out of the chat            text: <span onClick={event => this.handleSignOut(event)}>SignOut</span>        }    ];    handleSignOut = (event) => {        // You need to prevent form submission. Use event.preventDefault() in your handle submit function.        event.preventDefault();        firebase            .auth()            .signOut()            .then(() => console.log("See you"));    }     render(){        console.log(this.props.currentUser);        return (            <Grid style={{ background: '#4c3c4c' }}>                <Grid.Column>                    <Grid.Row style={{ padding: '1.2rem', margin: 0 }}>                        <Header inverted floated='left' as='h2'>                            <Icon name='code' />                            <Header.Content>VirtualChat</Header.Content>                        </Header>                    </Grid.Row>                    {/* User Dropdown Choices */}                    <Header style={{ padding: "0.25em" }} as="h4" inverted>                        <Dropdown                         trigger={<span>{this.state.user.displayName}</span>}                        options={this.dropdownOptions()}                        />                    </Header>                </Grid.Column>            </Grid>        )    }}
查看完整描述

2 回答

?
慕尼黑的夜晚無繁華

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

我認為該值是未定義的,因為您沒有檢查它是否props具有值,也許您嘗試呈現(xiàn)的數(shù)據(jù)尚未準備好或為async。為了解決這個問題,你可以設置你state的componentDidMount所以如果state.currentUser是null 這意味著數(shù)據(jù)還沒有準備好,你可以使裝載機或類似的東西。


class UserPanel extends React.Component {


    state = { user: null }


    dropdownOptions = () => [

        {

            key: "user",

            text: (

                <span>

                    Sign in as <strong>{this.state.user.displayName}</strong>

                </span>

            ),

            disabled: true

        },

        {

            key: "avatar",

            text: <span>Change Avatar</span>

        },

        {

            key: "signout",

            // Set a signout Function to enable user to sign out of the chat

            text: <span onClick={event => this.handleSignOut(event)}>SignOut</span>

        }

    ];


    handleSignOut = (event) => {

        // You need to prevent form submission. Use event.preventDefault() in your handle submit function.

        event.preventDefault();

        firebase

            .auth()

            .signOut()

            .then(() => console.log("See you"));

    } 

    componentDidMount(){

     this.setState({ user: this.props.currentUser })

    }

    render(){

        if( !this.state.user){

          return <div>Curernt User doesnt exist!</div>

        }

        return (

            <Grid style={{ background: '#4c3c4c' }}>

                <Grid.Column>

                    <Grid.Row style={{ padding: '1.2rem', margin: 0 }}>

                        <Header inverted floated='left' as='h2'>

                            <Icon name='code' />

                            <Header.Content>VirtualChat</Header.Content>

                        </Header>

                    </Grid.Row>



                    {/* User Dropdown Choices */}

                    <Header style={{ padding: "0.25em" }} as="h4" inverted>

                        <Dropdown 

                        trigger={<span>{this.state.user.displayName}</span>}

                        options={this.dropdownOptions()}

                        />

                    </Header>

                </Grid.Column>

            </Grid>

        )

    }

}


查看完整回答
反對 回復 2021-11-12
?
梵蒂岡之花

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

你打電話this.props.state.user而不是this.state.user


查看完整回答
反對 回復 2021-11-12
  • 2 回答
  • 0 關注
  • 184 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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