Refresh previous screen on goBack()

前端 未结 11 1833
天命终不由人
天命终不由人 2020-12-13 09:34

I am new to React Native. How can we refresh/reload previous screen when returning to it by calling goBack()?

Lets say we have 3 screens A, B, C:

<
11条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-13 10:01

    The built in listener function which comes with React-Navigation would be the easiest solution. Whenever a component is 'focused' on a again by navigating back, the listener will fire off. By writing a loadData function that can be called both when loading the Component AND when the listener is notified, you can easily reload data when navigating back.

       componentWillMount(){
        this._subscribe = this.props.navigation.addListener('didFocus', () => {
         this.LoadData();
         //Put your Data loading function here instead of my this.LoadData()
        });}
    

提交回复
热议问题