Skip to content

Commit 8d2a4cb

Browse files
committed
Use ES6 syntax instead of React.createClass
1 parent 35b1efa commit 8d2a4cb

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

src/PlotlyComponent.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import PropTypes from 'prop-types';
22
import React from 'react';
33
import cloneDeep from 'lodash.clonedeep';
44

5-
let createPlotlyComponent = (plotlyInstance) => React.createClass({
6-
displayName: 'Plotly',
7-
propTypes: {
5+
let createPlotlyComponent = (plotlyInstance) => class Plotly extends React.Component {
6+
7+
static propTypes = {
88
data: PropTypes.array,
99
layout: PropTypes.object,
1010
config: PropTypes.object,
@@ -13,9 +13,9 @@ let createPlotlyComponent = (plotlyInstance) => React.createClass({
1313
onHover: PropTypes.func,
1414
onUnHover: PropTypes.func,
1515
onSelected: PropTypes.func
16-
},
16+
};
1717

18-
attachListeners: function() {
18+
attachListeners() {
1919
if (this.props.onClick)
2020
this.container.on('plotly_click', this.props.onClick);
2121
if (this.props.onBeforeHover)
@@ -26,18 +26,18 @@ let createPlotlyComponent = (plotlyInstance) => React.createClass({
2626
this.container.on('plotly_unhover', this.props.onUnHover);
2727
if (this.props.onSelected)
2828
this.container.on('plotly_selected', this.props.onSelected);
29-
},
29+
}
3030

3131
shouldComponentUpdate(nextProps) {
3232
//TODO logic for detecting change in props
3333
return true;
34-
},
34+
}
3535

3636
componentDidMount() {
3737
let {data, layout, config} = this.props;
3838
plotlyInstance.newPlot(this.container, data, cloneDeep(layout), config); //We clone the layout as plotly mutates it.
3939
this.attachListeners();
40-
},
40+
}
4141

4242
componentDidUpdate(prevProps) {
4343
//TODO use minimal update for given changes
@@ -46,17 +46,17 @@ let createPlotlyComponent = (plotlyInstance) => React.createClass({
4646
plotlyInstance.newPlot(this.container, data, cloneDeep(layout), config); //We clone the layout as plotly mutates it.
4747
this.attachListeners();
4848
}
49-
},
49+
}
5050

51-
componentWillUnmount: function() {
51+
componentWillUnmount() {
5252
plotlyInstance.purge(this.container);
53-
},
53+
}
5454

55-
resize: function() {
55+
resize() {
5656
plotlyInstance.Plots.resize(this.container);
57-
},
57+
}
5858

59-
render: function () {
59+
render() {
6060
let {data, layout, config, ...other } = this.props;
6161
//Remove props that would cause React to warn for unknown props.
6262
delete other.onClick;
@@ -67,6 +67,6 @@ let createPlotlyComponent = (plotlyInstance) => React.createClass({
6767

6868
return <div {...other} ref={(node) => this.container=node} />
6969
}
70-
});
70+
};
7171

7272
export default createPlotlyComponent;

0 commit comments

Comments
 (0)