top of page
Writer's pictureJino Shaji

React-native setState

Updated: Jun 9, 2020




/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 * @flow
 */
import React, { Component } from ‘react’;
import {
Platform,
StyleSheet,
Text,
View,Button
} from ‘react-native’;
const instructions = Platform.select({
ios: ‘Press Cmd+R to reload,\n +
‘Cmd+D or shake for dev menu’,
android: ‘Double tap R on your keyboard to reload,\n +
‘Shake or press menu button for dev menu’,
});

// Note that component that receive Props is deprecated

type Props = {};
export default class App extends Component<Props> {
state={count: 0};
handlePressCounter= ()=>{
this.setState({count: this.state.count+1});
};
render() {
return (
<View style={styles.container}>
<Text style={styles.welcome}>
Count : {this.state.count}
</Text>
<Button title=“Counter” color=“#841584” onPress={this.handlePressCounter}
accessibilityLabel=“Learn more about this purple button” />
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: ‘center’,
alignItems: ‘center’,
backgroundColor: ‘#F5FCFF’,
},
welcome: {
fontSize: 20,
textAlign: ‘center’,
margin: 10,
},
instructions: {
textAlign: ‘center’,
color: ‘#333333’,
marginBottom: 5,
},
});

0 views0 comments

Recent Posts

See All

Redux-Thunk Small Overview

Introduction Redux Thunk middleware allows you to write action creators that return a function instead of an action. The thunk can be...

Comentarios


bottom of page