Skip to content

Instantly share code, notes, and snippets.

@jsmanifest
Created July 3, 2019 16:06
Show Gist options
  • Save jsmanifest/4b568cf451e44bce6c0488124b15c541 to your computer and use it in GitHub Desktop.
Save jsmanifest/4b568cf451e44bce6c0488124b15c541 to your computer and use it in GitHub Desktop.
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