ConfirmBattleContainer.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import React from "react";
  2. import ConfirmBattle from "../components/ConfirmBattle";
  3. import githubHelpers from "../utils/githubHelpers";
  4. class ConfirmBattleContainer extends React.Component {
  5. constructor(props) {
  6. console.log("Constructor (getInitialState)");
  7. super(props);
  8. this.state = {
  9. isLoading: true,
  10. playerInfo: []
  11. };
  12. }
  13. componentWillMount() {
  14. console.log("componentWillMount");
  15. }
  16. componentDidMount() {
  17. console.log("componentDidMount");
  18. const query = this.props.location.query;
  19. // Fetch info from Github then update state.
  20. githubHelpers.getPlayersInfo([query.playerOne, query.playerTwo])
  21. .then((info) => {
  22. this.setState({
  23. isLoading: false,
  24. playerInfo: info
  25. });
  26. });
  27. }
  28. componentWillReceiveProps() {
  29. console.log("componentWillReceiveProps");
  30. }
  31. componentWillUnmount() {
  32. console.log("componentWillUnmount");
  33. }
  34. componentWillUpdate(nextProps, nextState) {
  35. console.log("componentWillUpdate: loading ?", nextState.isLoading);
  36. }
  37. render() {
  38. return (
  39. <ConfirmBattle
  40. isLoading={this.state.isLoading}
  41. playerInfo={this.state.playerInfo}
  42. />
  43. );
  44. }
  45. }
  46. ConfirmBattleContainer.contextTypes = {
  47. router: React.PropTypes.object.isRequired
  48. };
  49. export default ConfirmBattleContainer;