{"size": 2199, "ext": "js", "max_stars_repo_path": "src/pages/Home.js", "max_stars_repo_name": "ludejun/ReactNative-Redux-Thunk", "max_stars_repo_stars_event_min_datetime": "2019-02-26T06:57:40.000Z", "max_stars_repo_stars_event_max_datetime": "2019-08-27T21:20:31.000Z", "max_issues_repo_path": "src/pages/Home.js", "max_issues_repo_name": "ludejun/ReactNative-Redux-Thunk", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/pages/Home.js", "max_forks_repo_name": "ludejun/ReactNative-Redux-Thunk", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 6, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 25.5697674419, "max_line_length": 95, "alphanum_fraction": 0.6321055025}
import React, { Component } from 'react';
import { Platform, StyleSheet, Text, View, Button } from 'react-native';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import * as homeActions from '../actions/home';

const instructions = Platform.select({
  ios: 'Press Cmd+R to reload,\nCmd+D or shake for dev menu',
  android: 'Double tap R on your keyboard to reload,\nShake or press menu button for dev menu',
});

type Props = {};
class Home extends Component<Props> {
  static navigationOptions = {
    title: '首页',
  };
  // constructor(props) {
  //   super(props);
  // }

  componentDidMount() {
    console.log('🎉🎉🎉🔥');
  }

  onIncrement = () => this.props.homeActions.homeAdd(this.props.count);
  onDecrement = () => this.props.homeActions.homeDecrement(this.props.count);

  render() {
    return (
      <View style={styles.container}>
        <Text style={styles.welcome}>Welcome to React Native!</Text>
        <Text style={styles.instructions}>To get started, edit App.js</Text>
        <Text style={styles.instructions}>{instructions}</Text>
        <View style={styles.reduxSample}>
          <Button title=" + " style={styles.flexItem} onPress={this.onIncrement} />
          <Text style={styles.flexItem}> {this.props.count} </Text>
          <Button title=" - " style={styles.flexItem} onPress={this.onDecrement} />
        </View>
      </View>
    );
  }
}

const mapStateToProps = ({ home }) => ({
  count: home.count,
});
const mapDispatchToProps = dispatch => ({
  homeActions: bindActionCreators(homeActions, dispatch),
});

export default connect(
  mapStateToProps,
  mapDispatchToProps
)(Home);

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,
  },
  reduxSample: {
    flex: 0,
    width: 200,
    height: 50,
    flexDirection: 'row',
    justifyContent: 'space-between',
    alignItems: 'center',
  },
  flexItem: {
    flex: 1,
    textAlign: 'center',
  },
});
