0

What is the "smart/assumed" way to pass username and change setUsername in this case from/between the parent and friend component?

From what I understand it doesn't work the same with sharing from App.js when I use react navigation(?) so assume that the app includes only 3 components that share and sets state - would I have to use context/redux for this? Thank you

App.js

const [username, setUsername] = useState('Testname'); 

        <Stack.Screen name="Parent" component={Parent}/>
        <Stack.Screen name="Friend" component={Friend}/>

Parent.js

export const Parent = ({navigation}) => {
return(
            <View style={styles.container}>
                <Text>Hello user:</Text>
                <Button title="go to friend" onPress={()=>navigation.navigate("Friend")}/>
            </View>

Friend.js

export const Friend = () => {
return(
    <TouchableOpacity>
        <Text>This is the Friend page</Text>
   <TouchableOpacity>
Ollie
  • 213
  • 1
  • 2
  • 14

1 Answers1

0

From what I understood the best approach is to use Context/Hooks.

Ollie
  • 213
  • 1
  • 2
  • 14