Passing values from one function to another with React navigation 5

Vincent

I would like to pass the value "Hello" from App.js to screen1.js. Snack: https://snack.expo.io/@mobshed/passing-data-between-functions

Thank you for your help!

App.js

import React, { useState, useEffect, Component } from "react";
import MyScreen from './screen1'

export default function Root() {
    return <MyScreen show="Hello" />;
}

screen1.js

import { NavigationContainer } from "@react-navigation/native";
import {
  createStackNavigator
} from "@react-navigation/stack";
const Stack = createStackNavigator();

function screenPage ({show}) {
  alert(show)
  return (<View style={{ justifyContent: "center", flex: 1}}><Text>Hello world</Text></View>)
}

export default function Root({ navigation }) {
  return (
    <NavigationContainer>
    <Stack.Navigator
      screenOptions={{
        headerTitleAlign: "center",
        gestureEnabled: false,
        gestureDirection: "horizontal"
      }}
    >
      <Stack.Screen
        options={{
          headerShown: false
        }}
        name="screenPage"
        component={screenPage}
      />   
    </Stack.Navigator>
     </NavigationContainer>
  );
}
Khanh Le Tran

in screen1.js:

import { NavigationContainer } from "@react-navigation/native";
import {
  createStackNavigator
} from "@react-navigation/stack";
const Stack = createStackNavigator();

function screenPage ({route}) {
  const {show} = route.params;
  alert(show);
  return (<View style={{ justifyContent: "center", flex: 1}}><Text>Hello world</Text></View>)
}

export default function Root({ navigation, show }) {
  return (
    <NavigationContainer>
    <Stack.Navigator
      screenOptions={{
        headerTitleAlign: "center",
        gestureEnabled: false,
        gestureDirection: "horizontal"
      }}
    >
      <Stack.Screen
        options={{
          headerShown: false
        }}
        name="screenPage"
        component={screenPage}
        initialParams={{show: show}}
      />   
    </Stack.Navigator>
     </NavigationContainer>
  );
}

Another way, you can pass params something like this:

<Button
        title="Done"
        onPress={() => {
          // Pass params back to screenPage
          navigation.navigate('screenPage', { show: "hello" });
        }}
      />

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Passing values from one function to another function

From Javascript

Passing data from one function to another in React

From Dev

Passing two values from one Matlab function to another in one line

From Dev

Passing a value from one function to another function in React.js

From Dev

Passing function in React.js from one function component to another

From Dev

Passing string parameters into function from one component to another in react

From

Passing function as a param in react-navigation 5

From Dev

Passing a variable from one function to another function

From Dev

Passing values from a function to another function

From Java

Passing over values from one method to another on

From Dev

WinForms - Passing values from one Form to another

From Dev

Passing values from one place to another

From Dev

passing values from one jInternalFrame to another jInternalFrame

From Dev

JAVA: Passing values from one class to another

From Dev

Passing Results from one React JS Function To Another React JS Function

From Dev

Passing state from one React Component to another

From Dev

Trouble passing links from one function to another

From Dev

Passing variable value from one function to another

From Dev

Passing a range from one VB function to another

From Dev

Passing lists from one function to another in Swift

From Dev

Passing values from a function to another in JS

From Dev

How do i go from one stack to another containing a tab stack in React Navigation 5.x?

From Dev

Passing params in React Navigation 5

From Dev

Passing a Variable from one JS function to another function

From Dev

Passing value from one function to another function in C

From Dev

Calling one function in another and passing it id, react + redux

From Dev

Use values from one javascript function into another

From Java

How to display values passing from one activity in another activity?

From Dev

Passing posted values from one controller to another in symfony

Related Related

  1. 1

    Passing values from one function to another function

  2. 2

    Passing data from one function to another in React

  3. 3

    Passing two values from one Matlab function to another in one line

  4. 4

    Passing a value from one function to another function in React.js

  5. 5

    Passing function in React.js from one function component to another

  6. 6

    Passing string parameters into function from one component to another in react

  7. 7

    Passing function as a param in react-navigation 5

  8. 8

    Passing a variable from one function to another function

  9. 9

    Passing values from a function to another function

  10. 10

    Passing over values from one method to another on

  11. 11

    WinForms - Passing values from one Form to another

  12. 12

    Passing values from one place to another

  13. 13

    passing values from one jInternalFrame to another jInternalFrame

  14. 14

    JAVA: Passing values from one class to another

  15. 15

    Passing Results from one React JS Function To Another React JS Function

  16. 16

    Passing state from one React Component to another

  17. 17

    Trouble passing links from one function to another

  18. 18

    Passing variable value from one function to another

  19. 19

    Passing a range from one VB function to another

  20. 20

    Passing lists from one function to another in Swift

  21. 21

    Passing values from a function to another in JS

  22. 22

    How do i go from one stack to another containing a tab stack in React Navigation 5.x?

  23. 23

    Passing params in React Navigation 5

  24. 24

    Passing a Variable from one JS function to another function

  25. 25

    Passing value from one function to another function in C

  26. 26

    Calling one function in another and passing it id, react + redux

  27. 27

    Use values from one javascript function into another

  28. 28

    How to display values passing from one activity in another activity?

  29. 29

    Passing posted values from one controller to another in symfony

HotTag

Archive