Advertisement
Guest User

Untitled

a guest
Jul 28th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. import React, { PropTypes } from "react";
  2. import { connect } from "react-redux";
  3. import StatelessComponent from "../components/StatelessComponent";
  4. import { apiCall } from "../utils";
  5.  
  6. export class Container extends React.Component {
  7. constructor(props) {
  8. /** Calling super() so we can use 'this' in the constructor */
  9. super(props);
  10.  
  11. /** Default state */
  12. this.state = {
  13. isValid: false,
  14. isError: false,
  15. };
  16.  
  17. /** Binding methods w/ this */
  18. this.componentMethod = this.componentMethod.bind(this);
  19. }
  20.  
  21. componentMethod() {
  22. apiCall()
  23. .then(res => {
  24. this.setState({isValid: true});
  25. // Connect passes in dispatch() via props
  26. this.props.dispatch({type: 'SOME_ACTION', data: res});
  27. })
  28. .catch(err => {
  29. this.setState({isError: true;});
  30. });
  31. }
  32.  
  33. render() {
  34. const { isError, isValid } = this.state;
  35.  
  36. return (
  37. <StatelessComponent isValid={isValid} isError={isError} />
  38. );
  39. }
  40. }
  41.  
  42. /** We're not passing mapStateToProps or mapDispatchToProps because all we need is just dispatch() */
  43. export default connect()(Container);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement