See the mistake below

0 comments

Please correct the mistakes I tried to let it render but it is not rendering anything

Here is the code:

import React, { Component } from ‘react’

import {

AppRegistry,

StyleSheet,

TouchableOpacity,

Text,

View,

} from ‘react-native’

class App extends Component {

constructor(props) {

super(props)

this.state = { count: 0 }

}

onPress = () => {

this.setState({

count: this.state.count+1

})

}

render() {

return (

<View style={styles.container}>

<TouchableOpacity

style={styles.button}

onPress={this.onPress}

>

<Text> Touch Here </Text>

</TouchableOpacity>

<View style={[styles.countContainer]}>

<Text style={[styles.countText]}>

{ this.state.count !== 0 ? this.state.count: null}

</Text>

</View>

</View>

)

}

}

const styles = StyleSheet.create({

container: {

flex: 1,

justifyContent: ‘center’,

paddingHorizontal: 10

},

button: {

alignItems: ‘center’,

backgroundColor: ‘#DDDDDD’,

padding: 10

},

countContainer: {

alignItems: ‘center’,

padding: 10

},

countText: {

color: ‘#FF00FF’

}

})

AppRegistry.registerComponent(‘App’, () => App)

https://facebook.github.io/react-native/docs/touch…

Here is an example to see how it should look like

About the Author

Follow me


{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}