Refresh previous screen on goBack()

前端 未结 11 1786
天命终不由人
天命终不由人 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:02

    How about using useIsFocused hook?

    https://reactnavigation.org/docs/function-after-focusing-screen/#re-rendering-screen-with-the-useisfocused-hook

    const componentB = (props) => { 
      // check if screen is focused
      const isFocused = useIsFocused();
    
      // listen for isFocused, if useFocused changes 
      // call the function that you use to mount the component.
    
      useEffect(() => {
        updateSomeFunction()
      },[isFocused]);
    }
    

提交回复
热议问题