Passing data between screens is a common requirement in React Native applications. Using navigation libraries like React Navigation, data can be sent from one screen to another using route parameters.
In React Navigation, data is passed while navigating using the navigate function. The target screen receives this data through the route.params object.
// Navigating and passing data to another screen
navigation.navigate("Profile", {
username: "Meghraj",
age: 25
});
// Receiving passed data in target screen
const { username, age } = route.params;
The Profile screen will display the username Meghraj and age 25 that were sent from the previous screen.
Select a user from the list below to "navigate" to their profile. This simulates passing the User ID and Name to the next screen via route.params.
Select a user to view details:
Received Name:
Received ID: