1

Im an working on React Native application. I have two different screens, Login and Register. Both the components are present in different modules. But, when I add onPress prop to the button in one screen, it is affecting the other screen also. For ex, if I click button of login screen, it is calling function of register screen, even there is no such event added for login screen button.

Please look at the code blocks,

LoginForm.js

<TouchableOpacity style={styles.buttonContainerRegister} onPress = {() => this.props.navigation.navigate('RegisterScreen')}>
                        <Text  style={styles.buttonText}>REGISTER</Text>
                    </TouchableOpacity>

RegisterForm.js

<TouchableOpacity style={styles.buttonContainerRegister1}  testID="test1" >
                            <Text  style={styles.buttonText1} onPress = {Alert.alert("my")} >Register</Text>
                        </TouchableOpacity>

When I click button of LoginForm.js, it is triggering event add for RegisterForm.js button.

1 Answer 1

4

In your RegisterForm.js, change this..

onPress = {Alert.alert("my")} //Self invoking

to this

onPress = {() => Alert.alert("my")} //Requires a Press event
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.