React Native - Force ListView Re-render when data has not changed

后端 未结 5 1123
后悔当初
后悔当初 2020-12-30 08:07

Is it possible to force a ListView to re-render, even if the data in the dataSource has not changed? I have a ListView within a tab bar in my app and I want it to redraw eve

5条回答
  •  再見小時候
    2020-12-30 08:33

    You can call this.forceUpdate() to force a re-render.

    You can do this in a simple onClick handler that you attach to the tab.

    More info here, on the official docs

    However, if there are other rules dictating if there should be an update or not, you can try replacing the dataSource altogether with a new one, making it have a new reference. That will also make it update.

    Something along the lines of

    this.setState({ data : newDataSource… });

提交回复
热议问题