General question for React interacting with javascript libraries. How can I use a function defined in React inside a javascript object. Is there a jQuery or pure react way?
Example:
I am using a highcharts-react-official library that is just a react wrapper around a JS library.
You would use it like:
const options = {
plotOptions: {
series: {
point: {
events: {
click: (e) => {
console.log(e.point.name); console.log(e.point.category); console.log(e.point.y);
this.handleFilter(); //NEED TO CALL THIS FUNCTION
}
}
}
}
}
class ChartComponent extends React.Component {
constructor() {
super();
this.state = {
someData: []
};
this.handleFilter = this.handleFilter.bind(this); //doesn't seem to work
}
handleFilter() {
console.log('Filter Triggered');
//EDIT -- Needs to be able to setState of this component here:
this.setState({someData: []});
}
render() {
return (
<div>
<HighchartsReact
highcharts={Highcharts}
options={options}
/>
</div>
);
}
}
How can I use handleFilter within that object?