我想将值“Hello”从 App.js 传递给 screen1.js。小吃:https ://snack.expo.io/@mobshed/passing-data-between-functions
谢谢您的帮助!
应用程序.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>
);
}