I have a class Display that uses values from a helper.js file for all its data and utilities. I am facing a problem where I need to call a method of the class from a function helper.js. Here is what I am trying to achieve:
class Display extends Component {
constructor(props) {
super(props);
this.imgHandler = this.imgHandler.bind(this);
}
imgHandler() {
const displayValues = this.getValues();
this.setState({
displayValues
});
}
}
helper.js
function renderIcon() {
return (
<img onClick={addHandler} />
)
}
I tried creating an instance of Display in helper.js and setting the onClick handler in renderIcon as follows:
const display = new Display();
<img onClick={display.imgHandler}>
But doing this gave me an error:
ReferenceError: can't access lexical declaration display before initialization
Could I please get some help with accomplishing the above? Thanks!