UNPKG

async-connect

Version:

HOC for calling and statusing redux actions on componentDidMount

33 lines (25 loc) 590 B
import React from 'react' import { object } from 'prop-types' import { getDeps } from './lib' export default depsMapper => Component => { class AsyncConnect extends React.Component { componentDidMount () { this._getDeps(this.props) } componentWillReceiveProps (next) { this._getDeps(next) } _getDeps (props) { getDeps(depsMapper, { ...props, ...this.context }) } render () { return ( <Component {...this.props} /> ) } } AsyncConnect.contextTypes = { store: object.isRequired } return AsyncConnect }