@@ -17,6 +17,7 @@ export default class Clipboard extends React.Component {
1717 constructor ( props ) {
1818 super ( props ) ;
1919 this . copyToClipboard = this . copyToClipboard . bind ( this ) ;
20+ this . onClickHandler = this . onClickHandler . bind ( this ) ;
2021 this . copySuccess = this . copySuccess . bind ( this ) ;
2122 this . getTargetText = this . getTargetText . bind ( this ) ;
2223 this . loading = this . loading . bind ( this ) ;
@@ -26,12 +27,19 @@ export default class Clipboard extends React.Component {
2627 } ;
2728 }
2829
30+ onClickHandler ( ) {
31+ this . props . setProps ( { n_clicks : this . props . n_clicks + 1 } ) ;
32+ }
33+
2934 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+ ) {
3240 return ;
3341 }
34- // If the data has changed, copy to clipboard
42+ // If the clicks has changed, copy to clipboard
3543 this . copyToClipboard ( ) ;
3644 }
3745
@@ -94,10 +102,6 @@ export default class Clipboard extends React.Component {
94102 }
95103
96104 async copyToClipboard ( ) {
97- this . props . setProps ( {
98- n_clicks : this . props . n_clicks + 1 ,
99- } ) ;
100-
101105 let content ;
102106 let htmlContent ;
103107 if ( this . props . target_id ) {
@@ -131,7 +135,7 @@ export default class Clipboard extends React.Component {
131135 title = { title }
132136 style = { style }
133137 className = { className }
134- onClick = { this . copyToClipboard }
138+ onClick = { this . onClickHandler }
135139 data-dash-is-loading = {
136140 ( loading_state && loading_state . is_loading ) || undefined
137141 }
0 commit comments