Prevent memory leak from selected account copy tooltip

feature/default_network_editable
David Walsh 4 years ago
parent 046b495670
commit 25a599c6cd
  1. 13
      ui/app/components/app/selected-account/selected-account.component.js

@ -18,6 +18,17 @@ class SelectedAccount extends Component {
selectedIdentity: PropTypes.object.isRequired,
}
componentDidMount () {
this.copyTimeout = null
}
componentWillUnmount () {
if (this.copyTimeout) {
clearTimeout(this.copyTimeout)
this.copyTimeout = null
}
}
render () {
const { t } = this.context
const { selectedIdentity } = this.props
@ -34,7 +45,7 @@ class SelectedAccount extends Component {
className="selected-account__clickable"
onClick={() => {
this.setState({ copied: true })
setTimeout(() => this.setState({ copied: false }), 3000)
this.copyTimeout = setTimeout(() => this.setState({ copied: false }), 3000)
copyToClipboard(checksummedAddress)
}}
>

Loading…
Cancel
Save