I have a print function, it first sets the state of isPrinting
to true and open a pring dialog. Once the dialog is being closed it sets the state of isPrinting
to false
and at this point I'm getting the error (second setState
):
Uncaught ReferenceError: setState is not defined
I binded function to current context with the arrow function.
handlePrint = () => {
this.setState({ isPrinting: true }, () => { //setState is working working properly
window.print();
if (window.matchMedia) {
var mediaQueryList = window.matchMedia('print');
mediaQueryList.addListener = (mql) => {
if (!mql.matches) {
this.setState({ isPrinting: false }); //Error
}
}
}
});
};