SHARE
TWEET

Untitled

a guest Mar 20th, 2017 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React, { Component } from 'react'
  2.  
  3. class ConfirmButton extends Component {
  4.   state = {
  5.     sure: false
  6.   }
  7.  
  8.   handleReallySure = event => {
  9.     event.preventDefault()
  10.  
  11.     const { onReallySure, reallySureMessage } = this.props
  12.     window.confirm(reallySureMessage) ? onReallySure() : this.setState({ sure: false })
  13.   }
  14.  
  15.   handleNotSure = event => {
  16.     event.preventDefault()
  17.     this.setState({ sure: false })
  18.   }
  19.  
  20.   render() {
  21.     const { sure } = this.state
  22.     const { children } = this.props
  23.  
  24.     return sure ?
  25.       <div className="confirm">
  26.         Are you sure?
  27.         <a href="#" onClick={this.handleReallySure}>Yes</a>
  28.         /
  29.         <a href="#" onClick={this.handleNotSure}>No</a>
  30.       </div>
  31.       :
  32.       <button className="confirm" onClick={() => this.setState({ sure: true })}>
  33.         {children}
  34.       </button>
  35.   }
  36. }
  37.  
  38. export default ConfirmButton
RAW Paste Data
Pastebin PRO Summer Special!
Get 40% OFF on Pastebin PRO accounts!
Top