I’m again asking a question regarding ReactNative: I have the following App.js:
export default function App() {
function Tabs() {
return <TabBar />;
}
const styles = StyleSheet.create({
backButton: {
color: global.GUI.ORANGE,
},
});
return (
<NavigationContainer>
<Stack.Navigator>
<Stack.Screen
name="Tabs"
component={Tabs}
..
/>
<Stack.Screen
name="Impostazioni"
component={Settings}
...
/>
<Stack.Screen
name="Registrati"
component={Signup}
...
/>
<Stack.Screen
name="Login"
component={Login}
...
/>
</Stack.Navigator>
</NavigationContainer>
);
}
I want to pass to each component some values declared in App.js,but doing something like:
<Stack.Screen
name="Impostazioni"
component={Settings}
currentUser={"name":"test"}
/>
Return undefined in:
import React from 'react';
import {View,Text} from 'react-native';
const Settings = (props) => {
--> console.log(props.currentUser) // here is undefined
return (
<View >
<Text>This is Settings!</Text>
</View>
);
};
export default Settings
So, how can I correctly pass props to App.js to all other components?
Thanks