import _isEmpty from "lodash/isEmpty"
import PropTypes from "prop-types"
import React, { Component } from "react"

const DictionaryField = WrappedComponent => {
  return class DictionaryField extends Component {
    static propTypes = {
      dictProps: PropTypes.object
    }

    render() {
      const { dictProps, ...otherProps } = this.props
      // Only display field if the dictProps are defined
      if (!_isEmpty(dictProps)) {
        return (
          <WrappedComponent {...Object.assign({}, dictProps, otherProps)} />
        )
      } else {
        return null
      }
    }
  }
}

export default DictionaryField

import _isEmpty from "lodash/isEmpty"
import PropTypes from "prop-types"
import React from "react"

const DictionaryField = WrappedComponent => ({ dictProps, ...otherProps }) => {
  // Only display field if the dictProps are defined
  if (!_isEmpty(dictProps)) {
    return <WrappedComponent {...Object.assign({}, dictProps, otherProps)} />
  } else {
    return null
  }
}
DictionaryField.propTypes = {
  dictProps: PropTypes.object
}

export default DictionaryField

Make DictionaryField a functional component