React Navigation 5.x Send Data From One Screen To Another React Native Example Tutorial

In react navigation data transfer format is a bit changed then older version. In React Navigation 5.x we would use navigation.navigate() method to navigate to next activity screen. We would also send multiple type of data along with this method. In this tutorial we would send multiple type of data integer and string to next activity screen and receive the data on next screen using route.params(). After receive data we would extract data and show all the data in Text component. So in this tutorial we would React Navigation 5.x Send Data From One Screen To Another React Native Example Tutorial.

Contents in this project React Navigation 5.x Send Data From One Screen To Another React Native Example Tutorial:

1. Before getting started with coding we have to manually install the latest version of React Navigation 5.x in our current react native project. I have also make a tutorial about installing react navigation in react native. So read my tutorial about Installing React Navigation 5.x in React Native Here.

2. After done installation react navigation 5.x, Open your project’s main App.js file and import react-native-gesture-handlerStyleSheetTextViewNavigationContainer and createStackNavigator components.

3. Create a function named as HomeScreen with navigation prop. This is our main First activity screen class.

4. Creating a function named as navigateToScreen() in HomeScreen. Here we would make our navigation.navigate() method and call the Second class and pass 3 different values along with it. We are sending studentId, studentName, studentClass to next screen.

5. Creating render’s return block in Home Screen. Now we would make a Button with Text component here and call navigateToScreen method on button click event.

6. Creating another function named as SecondScreen(). This is our Second screen with route and navigation prop. Here first we would receive the send items from home screen in constant variables and then show them in Text component.

7. Creating a createStackNavigator() named as Stack.

8. Creating another function named as App. Here we would pass our both screens and set their Screen name.

9. Creating Style.

10. Call our main export default class named as App.

11. Complete Source Code for App.js file:

Screenshots:

React Navigation 5.x Send Data From One Screen To Another React Native Example Tutorial

React Navigation 5.x Send Data From One Screen To Another React Native Example Tutorial

4 Comments

  1. Hii, sir
    How to create excel file from json array data??

  2. hi
    in your example (reactReact Navigation 5.x Call External JS Screen Files in App.js File React Native) in secondscreen i need want to a json listview i used code from your tutorial(React Native JSON FlatList with Images and Text) . it is not working . in reactnavigation 4 it was working properly.

    kindly provide a solution
    thank you

  3. Hi, I need to develop a library, in which input is received from react-native app and response is return respectively, share any example/tutorial link, Thanks in advanced.

Leave a Reply

Your email address will not be published. Required fields are marked *