Skip to content

Instantly share code, notes, and snippets.

@srph
Last active December 19, 2017 04:03
Show Gist options
  • Select an option

  • Save srph/a5fa79c126f9fde6cc775ea72b867fed to your computer and use it in GitHub Desktop.

Select an option

Save srph/a5fa79c126f9fde6cc775ea72b867fed to your computer and use it in GitHub Desktop.
react-confirmable idea // see https://github.com/srph/react-confirm
import {confirm, Confirm, ConfirmNode} from 'react-confirm';

// Root
<Confirm />

// Event handler
confirm('hi');

// In case you need to check if it's open or not
<ConfirmNode onOpen={} onClose={} />

Setup

class ConfirmModal extends React.Component {
  render() {
    if (!this.props.open) {
      return;
    }
            
    return (
      <Modal>
        {this.props.text}
      </Modal>
    )
  }
}

export default Confirmable(ConfirmModal);

Render Props

class ConfirmModal extends React.Component {
  render() {
    if (!this.props.open) {
      return;
    }
            
    return (
      <Confirm>
        {(open, text, options) =>
          <Modal>
            {this.props.text}
          </Modal>
        )}
      </Confirm>
    )
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment