Last active
December 16, 2017 15:35
-
-
Save olegkalyta/e795337dfb1bf2ae6febdcf668bcc491 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component, Children } from 'react' | |
import { connect } from 'react-redux' | |
import PropTypes from 'prop-types' | |
import { fetchPrograms } from '../../modules/loanPrograms' | |
class LoanProgramContainer extends Component { | |
componentDidMount() { | |
this.props.fetchPrograms() | |
} | |
render() { | |
const { programsWithMeta: { isFetching, error, programs }, children } = this.props | |
if (isFetching) { | |
return (<div>Loading...</div>) | |
} | |
if (error) { | |
return <div>{error}</div> | |
} | |
if (programs.length === 0) { | |
return <div>No programs</div> | |
} | |
const chilrenWithProps = Children.map(children, child => { | |
return React.cloneElement(child, { programs }) | |
}) | |
return <div>{chilrenWithProps}</div> | |
} | |
} | |
const connectedLoanProgramContainer = connect( | |
state => { | |
const { loanPrograms } = state | |
return { programsWithMeta: loanPrograms } | |
}, { fetchPrograms }) | |
(LoanProgramContainer) | |
export default connectedLoanProgramContainer |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment