在 navigator.pop() 上刷新组件 [英] Refresh Component on navigator.pop()

查看:36
本文介绍了在 navigator.pop() 上刷新组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 React Native 的导航器.无论如何要刷新组件,所以当我弹回它时,它会进行新的 API 调用并获取更新的数据以显示在组件中.我发现了一些类似的问题,但没有很好的答案...

I'm using React Native's Navigator. Is there anyway to refresh the component so when I pop back to it, it'll make a new API call and grab the updated data to display in the component. I found a few similar questions, but no good answer...

推荐答案

使用订阅在回调中添加 Api 调用.解决问题

Adding Api Call in callBack using a subscription. sovles the issue

  componentDidMount() {
     this.props.fetchData();        
     this.willFocusSubscription = this.props.navigation.addListener(
      'willFocus',
      () => {
        this.props.fetchData();
      }
    );
  }

  componentWillUnmount() {
    this.willFocusSubscription.remove();
  }

这篇关于在 navigator.pop() 上刷新组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆