Skip to content

Instantly share code, notes, and snippets.

@Bitaru
Last active January 22, 2018 16:24
Show Gist options
  • Save Bitaru/55ecf27affcfa931b8228a807dcdc0e6 to your computer and use it in GitHub Desktop.
Save Bitaru/55ecf27affcfa931b8228a807dcdc0e6 to your computer and use it in GitHub Desktop.
Findify Challenge

TASK:

Implement a "withModal" high order component (HOC) that will accept two arguments [modalName: String] and [modalComponent: React.Component]. It should render a "modalComponent" into the portal. In addition, this HOC should inject 'showModal' and 'hideModal' handlers into a new collection of props that are passed to the base component. For instance:

const PricingModal = ({ title, onHide }) => <button onClick={onHide}>Hide {title} modal</button>;

class PricingButton extends React.Component {
  showPricing: () => {
    const { openModal, hideModal } = this.props;
    openModal('pricing', {
      title: 'Pricing',
      onHide: (data) => hideModal('pricing')
    })
  }

  render() {
    return <button onClick={this.showPricing}>Open modal</button>
  }
}


export default withModal('pricing', PricingModal)(PricingButton)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment