I'm using react google charts and am trying to use the chartEvents
method to hook into the selection event.
This works:
const ChartClass = React.createClass({
getInitialState () {
return {
showModal: false
}
},
handleShowModal () {
this.setState((prev, props) => {
return {
showModal: true
}
})
},
chartEvents: [
{
eventName: 'select',
callback: function (Chart) {
this.handleShowModal()
}
}
],
render () {
return (
<Chart
chartEvents={this.chartEvents}
data={this.props.data}
/>
)
}
})
However within that callback I would like to call some other methods
this.handleOpenModal(ChartObj) // TypeError: this.handleOpenModal is not a function
this.sthElse()
because within this callback this
is being set to event itself
console.log(this) //object {eventName: "select", callback: function}
Is there any way to reference the parent class so I can use its methods? I don't think I can simply place the function outside of the class because it needs to use this.setState