Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class ReactNativeComponent extends React.Component {
- constructor(props) {
- super(props)
- this.state = {
- clicks: 0
- };
- }
- componentDidMount() {
- AppState.addEventListener('change', this.incrementClicks);
- }
- componentWillUnmount() {
- AppState.removeEventListener('change', this.incrementClicks);
- }
- // контекст со стрелочкой берется из окружения, а оно - текущий объект класса
- incrementClicks = () => {
- this.setState(prevState => {
- return {
- clicks: this.state.clicks + 1
- }
- });
- }
- render() {
- return (
- <View>
- <Text>{`My Component ${this.state.clicks} clicks`}</Text>
- <Text>this.props.headerText</Text>
- <TouchableHighlight
- underlayColor={colors.buttonsOverlayColor}
- onPress={this.incrementClicks}
- style={
- {
- width: 100,
- height: 100,
- backgroundColor:'red'
- }
- }/>
- </View>
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement