Mateusz
Mateusz

Reputation: 1

Value of props variable in react-native navigation

When I press first time on button, navigate to another screen with variable props.userGuid value is 0000000. Then navigate.goBack() from another screen. Then I change setState of variable userGuid to 12345678 and when press again button from function component, screen is load with old 0000000 value. Why navigate don't get new value, when in console.log is a new value visible?

const DetailsScreenButton = (props) => {
        return (<TouchableOpacity
             onPress={() => {
                console.log(props.userGuid)   <---------- here I have value 1234567 while second press
              
                navigation.navigate('DietDetails', {
                    userGuid: props.userGuid  <---------- here I have allways value 0000000 
                });
            }}
        >
            <Text>Show details</Text>
        </TouchableOpacity>)
    }



return (
    <Modal
        animationType="fade"
        transparent={true}
        visible={modalDetailsVisible}
    >
        <View style={styles.centeredView}>
            <View style={styles.modalView}>
               <DetailsScreenButton userGuid={userGuid} />
            </View>
        </View>
    </Modal>
)


Upvotes: 0

Views: 61

Answers (1)

Chefk5
Chefk5

Reputation: 469

You are changing the state but not updating the props. In other words you are not sending the new state in the props.

Please add the code where you change the state.

Upvotes: 1

Related Questions