index.jsx 824 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import React, { Component } from "react";
  2. import PropTypes from "prop-types";
  3. import { connect } from "react-redux";
  4. import { increment } from "actions/app";
  5. @connect(state => ({
  6. counter: state.app.get("counter"),
  7. }))
  8. export default class Home extends Component {
  9. static propTypes = {
  10. counter: PropTypes.number,
  11. dispatch: PropTypes.func,
  12. }
  13. static defaultProps = {
  14. counter: 0,
  15. dispatch: () => {},
  16. }
  17. constructor() {
  18. super();
  19. this.handleIncrement = this.handleIncrement.bind(this);
  20. }
  21. handleIncrement() {
  22. const { dispatch } = this.props;
  23. dispatch(increment());
  24. }
  25. render() {
  26. const {
  27. counter,
  28. } = this.props;
  29. return (
  30. <div>
  31. <h2>Welcome to Musare!</h2>
  32. <h3>{ counter }</h3>
  33. <button onClick={ this.handleIncrement }>
  34. Increase counter
  35. </button>
  36. </div>
  37. );
  38. }
  39. }