在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/HTML/ 用 antd mobile 的ListView的時候遇到的問題

用 antd mobile 的ListView的時候遇到的問題

Stateless function components cannot be given refs. Attempts to access this ref will fail.

 <div>
    <ListView
      ref={ el => this.lv = el }
      dataSource={ this.state.dataSource }
      renderScrollComponent={ () => <MyBody /> }
      renderRow={row}
      onEndReachedThreshold={100}
      onEndReached={this.getList}
      style={{
        height: '500px',
        overflow: 'auto',
      }}
    />
</div>

在使用的時候報這個錯  
而且為什么react有時候使用 refs 只能獲取組件實例   不能獲取真實的dom節(jié)點?
回答
編輯回答
尐飯團

這個異常的解決方式是把stateless組件修改為class。
但是你引用的是第三方的。所以這個方式應該無效。
所以你不能在ListView組件中用refs來獲取數(shù)據(jù),只能通過其他方式獲取,比如回調。

再次強調,使用react就忘掉真實dom吧。不要嘗試獲取真實dom,也不要操作真實Dom

2018年2月24日 18:05