Skip to content

Instantly share code, notes, and snippets.

@timdorr
Created March 21, 2017 04:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timdorr/ea2a403a7aa75d59251b8e0e6f1ecf39 to your computer and use it in GitHub Desktop.
Save timdorr/ea2a403a7aa75d59251b8e0e6f1ecf39 to your computer and use it in GitHub Desktop.
import React, { Component } from 'react'
class ConfirmButton extends Component {
state = {
sure: false
}
handleReallySure = event => {
event.preventDefault()
const { onReallySure, reallySureMessage } = this.props
window.confirm(reallySureMessage) ? onReallySure() : this.setState({ sure: false })
}
handleNotSure = event => {
event.preventDefault()
this.setState({ sure: false })
}
render() {
const { sure } = this.state
const { children } = this.props
return sure ?
<div className="confirm">
Are you sure?
<a href="#" onClick={this.handleReallySure}>Yes</a>
/
<a href="#" onClick={this.handleNotSure}>No</a>
</div>
:
<button className="confirm" onClick={() => this.setState({ sure: true })}>
{children}
</button>
}
}
export default ConfirmButton
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment