@@ -73,10 +73,12 @@ export default function createPlotlyComponent (Plotly) {
73
73
this . p = this . p . then ( ( ) => {
74
74
return ( hasReactAPIMethod ? Plotly . react : Plotly . newPlot ) ( this . el , {
75
75
data : nextProps . data ,
76
- layout : this . applySize ( this . props . layout ) ,
77
- config : this . props . config ,
78
- frames : this . props . frames ,
79
- } ) . then ( this . syncEventHandlers ) ;
76
+ layout : this . applySize ( nextProps . layout ) ,
77
+ config : nextProps . config ,
78
+ frames : nextProps . frames ,
79
+ } ) . then ( ( ) => {
80
+ this . syncEventHandlers ( nextProps )
81
+ } ) ;
80
82
} ) ;
81
83
}
82
84
@@ -112,14 +114,17 @@ export default function createPlotlyComponent (Plotly) {
112
114
}
113
115
114
116
// Attach and remove event handlers as they're added or removed from props:
115
- syncEventHandlers ( ) {
117
+ syncEventHandlers ( props ) {
118
+ // Allow use of nextProps if passed explicitly:
119
+ props = props || this . props ;
120
+
116
121
for ( let i = 0 ; i < eventNames . length ; i ++ ) {
117
122
const eventName = eventNames [ i ] ;
118
- const prop = this . props [ "on" + eventName ] ;
123
+ const prop = props [ "on" + eventName ] ;
119
124
const hasHandler = ! ! this . handlers [ eventName ] ;
120
125
121
126
if ( prop && ! hasHandler ) {
122
- let handler = ( this . handlers [ eventName ] = this . props [
127
+ let handler = ( this . handlers [ eventName ] = props [
123
128
"on" + eventName
124
129
] ) ;
125
130
this . el . on ( "plotly_" + eventName . toLowerCase ( ) , handler ) ;
0 commit comments