Created
July 3, 2019 16:06
-
-
Save jsmanifest/4b568cf451e44bce6c0488124b15c541 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
const withTotalCount = (WrappedComponent) => { | |
class WithTotalCountContainer extends React.Component { | |
componentDidMount = () => { | |
const { total, dispatch } = this.props | |
if (total == null) { | |
dispatch(fetchTotalVideoTypeCount()) | |
} | |
} | |
render() { | |
return <WrappedComponent {...this.props} /> | |
} | |
} | |
WithTotalCountContainer.propTypes = { | |
fetching: PropTypes.bool.isRequired, | |
total: PropTypes.number, | |
fetchError: PropTypes.object, | |
dispatch: PropTypes.func.isRequired, | |
} | |
WithTotalCountContainer.displayName = `withTotalCount(${getDisplayName( | |
WrappedComponent, | |
)})` | |
return connect((state) => { | |
const videoType = fixVideoTypeNaming(state.app.media.video.videoType) | |
const { fetching, total, fetchError } = state.app.media.video[ | |
videoType | |
].options.total | |
return { fetching, total, fetchError } | |
})(WithTotalCountContainer) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment