CopyToClipboard: clear timeout on unmount
This commit is contained in:
parent
a97e68a030
commit
acbaed59c0
@ -39,9 +39,17 @@ export default class CopyToClipboard extends Component {
|
||||
};
|
||||
|
||||
state = {
|
||||
copied: false
|
||||
copied: false,
|
||||
timeout: null
|
||||
};
|
||||
|
||||
componentWillUnmount () {
|
||||
const { timeoutId } = this.state;
|
||||
if (timeoutId) {
|
||||
window.clearTimeout(timeoutId);
|
||||
}
|
||||
}
|
||||
|
||||
render () {
|
||||
const { data, label, size } = this.props;
|
||||
const { copied } = this.state;
|
||||
@ -65,11 +73,12 @@ export default class CopyToClipboard extends Component {
|
||||
onCopy = () => {
|
||||
const { cooldown, onCopy } = this.props;
|
||||
|
||||
this.setState({ copied: true });
|
||||
setTimeout(() => {
|
||||
this.setState({ copied: false });
|
||||
}, cooldown);
|
||||
|
||||
this.setState({
|
||||
copied: true,
|
||||
timeout: setTimeout(() => {
|
||||
this.setState({ copied: false, timeout: null });
|
||||
}, cooldown)
|
||||
});
|
||||
onCopy();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user