react-nativeexpoexpo-router

expo router back to previous screen with data


i have a question regard grabbing the data in the previous screen after calling the router.back() in current screen. Let say i have Screen A and B. i used router.push() to go from screen A -> B after i finish editing in Screen B, i want to go back to Screen A with some data that i would like to pass back to Screen A. what i used to do is

  router.back();
  router.setParams({
      newValue: xxx
  });

Then in Screen A i use the useLocalSearchParams<{newValue: string}>(); to get the data passed from Screen B -> Screen A after a recent pacakage update, this method no longer work. i am not seeing the newValue in localSearchParam anymore. but i can still see the newValue in GlobalSearchParams my question is : am i doing to right thing to pass data back using setParams is there any other recommend approach? and is it the right thing to use GlobalSearchParams instead of localSearchParam

expo version: 53.0.20 expo router version: 5.1.4


Solution

  • the best solution i found:

    router.dismissTo({
        pathname:xxx
        params:{...}
    })