Advertisement
Guest User

Untitled

a guest
Mar 20th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement