亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

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

拉取以刷新并設置狀態不起作用 - 在本機做出反應

拉取以刷新并設置狀態不起作用 - 在本機做出反應

智慧大石 2022-09-11 20:18:24
反應本機應用程序我正在實現拉動以刷新我的 Flatlist 道具“onRefresh”,稱為函數“刷新控制()”,請參閱下面的代碼。在從 API 獲取之前,我需要將狀態“刷新”更改為 true。但它會引發最大的更新錯誤。export default class NotificationScreen extends Component {  constructor(props) {   super(props)   this.state = {      refreshing: false     }  }.....  refreshControl() {    const { refreshing } = this.state;    this.setState({ refreshing : true )}.    // throws maximum update error    return (      <RefreshControl        refreshing={refreshing}        onRefresh={fetchNotifications.bind(this)}      //fetch from API only when refreshing is true        colors={['#2B70AD']}      />    );  };}否則,如何將我的狀態設置為“刷新:true”???請幫忙!!!!這就是它的修復方式。溶液:refresh = async() => {    this.setState({refreshing : true})    try {      const notifications = await fetchNotifications();      this.setState({        notifications,        error: null,        refreshing: false      });    } catch (error) {      this.setState({        notifications: [],        error,        refreshing: false      });    }  }  refreshControl() {    const { refreshing } = this.state;    return (      <RefreshControl        refreshing={refreshing}        onRefresh={this.refresh}        colors={['#2B70AD']}      />    );  };
查看完整描述

3 回答

?
米脂

TA貢獻1836條經驗 獲得超3個贊

  refreshFlatlist = () => {

    this.setState(

      {

        refresh: true,

      },

      () => this.getTodosHandler()

    );

    this.setState({

      refresh: false,

    });

  };

這就是我刷新默認狀態的方式,當然是錯誤的。待辦事項處理程序始終持有當前待辦事項。這是對本地存儲在手機上的 SQLite 數據庫的調用。


現在我使用的簡單列表刷新組件:


   <FlatList

            refreshControl={

              <RefreshControl

                refreshing={this.state.refresh}

                onRefresh={this.refreshFlatlist}

              />

            }

            extraData={this.state.refresh}

            data={this.state.toDoArray}

            keyExtractor={(item, index) => item.id.toString()}

            renderItem={({ item }) => ( ... 

看看它也許它會幫助你 - 這對我來說就像一個魅力;)


查看完整回答
反對 回復 2022-09-11
?
人到中年有點甜

TA貢獻1895條經驗 獲得超7個贊

這可能不是問題,但我會把它放在這里給其他人(像我一樣)試圖調試:

確保您的列表未放入滾動視圖中!


查看完整回答
反對 回復 2022-09-11
?
搖曳的薔薇

TA貢獻1793條經驗 獲得超6個贊

這應該可以完美地工作。我認為您的代碼中存在拼寫錯誤。您正在使用 try 而不是 true。我認為這可能是錯誤的原因。


查看完整回答
反對 回復 2022-09-11
  • 3 回答
  • 0 關注
  • 88 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號