鍍金池/ 問答/HTML/ render()函數(shù)的return問題

render()函數(shù)的return問題

 render() {
    const users = this.props.chatMsg.users
    if(!users) {
      return null
    }
    console.log(users)
    return <div>{users}</div>
 }

users里面的數(shù)據(jù)是異步獲取的,在render函數(shù)中使用renturn null為什么沒用啊,還是會(huì)去執(zhí)行接下來的代碼

回答
編輯回答
詆毀你

你輸出的users是空的嗎?如果是的話,應(yīng)該沒問題的,我也用過

2017年12月19日 11:56
編輯回答
醉淸風(fēng)

那你把不需要執(zhí)行的代碼寫到else中就好了。

2017年12月10日 04:48
編輯回答
瘋浪
 render() {
    const users = this.props.chatMsg.users
    return (
       <div>
          {users?users:''}
        </div>
    )
 }
2017年10月24日 11:22