react-nativenavigationexpoexpo-router

How to pass data from a modal with Expo Router using React-Native


Newbie to expo-router & React-Native

I have two screens (a & b) for example, b being a modal which is presented over a.

How would I go about passing data from screen b (the modal) back to screen a?

File Structure

app
-(tabs)
--account
---index.jsx (screen a)
-create-account
--index.jsx (screen b)

Usually when you are adding a screen to the stack you would use useLocalSearchParams(); however, I am popping a screen off the stack and the screen behind is already rendered.


Solution

  • From the React Navigation docs: Passing params to a previous screen

    To achieve this, you can use the navigate method, which acts like goBack if the screen already exists. You can pass the params with navigate to pass the data back.