React Native Change Button Upper Title Text Using State Dynamically

React Native gives us 2 types of button designing technique, First one is its own Button component, Second is Custom Button using TouchableOpacity. So in this tutorial we would going to Change custom TouchableOpacity Button Upper Title Text programmatically using State.

What we are doing in this tutorial :

We are creating 2 buttons in our tutorial, First is Rounded corners button using TouchableOpacity and second is simple button. Now we would set the TouchableOpacity Button Above Title Text using State created in constructor(). We would also create a function to update – change button title state value.

Contents in this project Change Button Upper Title Text Using State:

1. Import StyleSheet, View, Button, Text and TouchableOpacity component in your project.

2. Create constructor() in your class with a State named as ButtonText. This state is used as Button Title Text.

3. Create a function named as ChangeButtonTitle(). In this function we would dynamically change the ButtonText State value.

4. Create a Root View in render’s return block, Now create a Custom button using TouchableOpacity. Inside the TouchableOpacity component we would set a Text component, Now set ButtonText State in Text component. This would be our Main Button which Text we would change.

4. Add a button and call the ChangeButtonTitle() function on button onPress event.

5. Create Style Classes:

6. Complete source code for App.js File :

Screenshot in Android device :


Button Upper Title TextScreenshot in iOS device :

Change Button Above Title Text