【问题标题】:What's the equivalent of window.reload() in react-native?react-native 中的 window.reload() 等价物是什么?
【发布时间】:2017-05-05 16:07:29
【问题描述】:

有没有办法在 react-native 中完全刷新整个场景而不更新状态或强制重新渲染?

例如:

refreshButton(){
    Actions.refresh()
}

P.S:我使用 react-native-router-flux 作为我的导航器。我确实尝试过Actions.refresh({key: "page_name"}),但没有成功。

【问题讨论】:

  • 为什么需要这样做?
  • 我想在手机再次重新连接到互联网时刷新列表视图。 @Scimonster
  • 所以需要更新状态。

标签: reactjs react-native react-native-router-flux


【解决方案1】:
import { NetInfo } from 'react-native';
// component did mount
NetInfo.isConnected.addEventListener(
    'change',
    this._handleConnectivityChange
);

_handleConnectivityChange = (isConnected) => {
this.setState({
  isConnected,
});
};
// remove listener on componentWillUnmount

更多信息here

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-13
    • 2020-04-23
    • 1970-01-01
    • 1970-01-01
    • 2016-11-08
    • 2019-03-29
    相关资源
    最近更新 更多