@@ -17,6 +17,7 @@ export default class Clipboard extends React.Component {
17
17
constructor ( props ) {
18
18
super ( props ) ;
19
19
this . copyToClipboard = this . copyToClipboard . bind ( this ) ;
20
+ this . onClickHandler = this . onClickHandler . bind ( this ) ;
20
21
this . copySuccess = this . copySuccess . bind ( this ) ;
21
22
this . getTargetText = this . getTargetText . bind ( this ) ;
22
23
this . loading = this . loading . bind ( this ) ;
@@ -26,12 +27,19 @@ export default class Clipboard extends React.Component {
26
27
} ;
27
28
}
28
29
30
+ onClickHandler ( ) {
31
+ this . props . setProps ( { n_clicks : this . props . n_clicks + 1 } ) ;
32
+ }
33
+
29
34
componentDidUpdate ( prevProps ) {
30
- // If the data hasn't changed, do nothing.
31
- if ( ! this . props . content || this . props . content === prevProps . content ) {
35
+ // If the clicks has not changed, do nothing
36
+ if (
37
+ ! this . props . n_clicks ||
38
+ this . props . n_clicks === prevProps . n_clicks
39
+ ) {
32
40
return ;
33
41
}
34
- // If the data has changed, copy to clipboard
42
+ // If the clicks has changed, copy to clipboard
35
43
this . copyToClipboard ( ) ;
36
44
}
37
45
@@ -94,10 +102,6 @@ export default class Clipboard extends React.Component {
94
102
}
95
103
96
104
async copyToClipboard ( ) {
97
- this . props . setProps ( {
98
- n_clicks : this . props . n_clicks + 1 ,
99
- } ) ;
100
-
101
105
let content ;
102
106
let htmlContent ;
103
107
if ( this . props . target_id ) {
@@ -131,7 +135,7 @@ export default class Clipboard extends React.Component {
131
135
title = { title }
132
136
style = { style }
133
137
className = { className }
134
- onClick = { this . copyToClipboard }
138
+ onClick = { this . onClickHandler }
135
139
data-dash-is-loading = {
136
140
( loading_state && loading_state . is_loading ) || undefined
137
141
}
0 commit comments