index.jsx 852 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. componentDidMount() {
  22. }
  23. handleIncrement() {
  24. const { dispatch } = this.props;
  25. dispatch(increment());
  26. }
  27. render() {
  28. const {
  29. counter,
  30. } = this.props;
  31. return (
  32. <div>
  33. <h2>Welcome to Musare!</h2>
  34. <h3>{ counter }</h3>
  35. <button onClick={ this.handleIncrement }>
  36. Increase counter
  37. </button>
  38. </div>
  39. );
  40. }
  41. }