Skip to content

Instantly share code, notes, and snippets.

@bigslycat
Forked from Bitaru/findify_challenge.md
Last active January 24, 2018 13:33
Show Gist options
  • Select an option

  • Save bigslycat/673bf3fb7165421ede81da134f3818a9 to your computer and use it in GitHub Desktop.

Select an option

Save bigslycat/673bf3fb7165421ede81da134f3818a9 to your computer and use it in GitHub Desktop.
Findify Challenge

TASK:

Write down a "withModal" high order component, which will accept two arguments [modalName: String] and [modalComponent: React.Component] and render modalComponent into portal. Also, this HOC should inject 'showModal' and 'hideModal' to a new collection of props that are passed to the base component. eq:

import { compose, withHandlers } from 'recompose';

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

const enhance = compose(
  withModal('pricing', PricingModal),
  withHandlers({
    showPricing: ({ openModal, hideModal }) => () => 
      openModal('pricing', {
        title: 'Pricing',
        onHide: (data) => hideModal('pricing')
      })
  })
)

export default enhance(({
  openModal
}) => (
  <button onClick={openModal}>Open modal</button>
))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment