Home > other >  Text value doesn't change in React Native app using Class Component
Text value doesn't change in React Native app using Class Component

Time:12-26

I have this react native app that shows the splash screen first and loads a home screen. The sample home screen shows text as "Demo Display" and I want to change it to "Text Changed!". I'm using a stateful class component. But everytime I try to restart/reinstall/debug the app the text remains same as "Demo Display". How can I fix this?

App.js

import React,{ Component } from 'react'
import { View, Text } from 'react-native'
import SplashScreen from 'react-native-splash-screen'

export default class App extends Component {

  componentDidMount() {
      SplashScreen.hide();
  }

  render() {
    return (
      <View>
        <Text>Text Changed!</Text>
      </View>
    );
  }
}

This is a screen shot of the app

CodePudding user response:

Your text is there on the screen but it will not replace the default text. Give some style to your main View and you will see your text there. Try,

<View style={{justifyContent: 'center',alignItems: 'center'}}> <Text>Text Changed!</Text> </View>

  • Related