Answer the question
In order to leave comments, you need to log in
How to get around the react-progress-2 error?
Hi all!
I ran into a problem: I put a loader in the header of the page " react-progress-2 " in my application.
Here's a plan.
Everything works on one page, but if I go from one page to another, I get an error:
And it doesn’t matter if I call this function in a didmount or on a click or another event, the result is the same.
import Progress from "react-progress-2";
import "react-progress-2/main.css"
loadPage = () => {
Progress.show();
setTimeout(() => Progress.hideAll(),800);
}
<Progress.Component/>
Answer the question
In order to leave comments, you need to log in
1. You can only use one component per page, as the reference to the instance is written in the prototype .
2. The reason for the error is that you do not clear the timeout during the transition. First , the reference to the instance is removed , then your timeout is triggered and the method of the non- existent reference is called. To get rid of the error, it is enough to clear the timeout in componentWillUnmount:
loadPage = () => {
Progress.show();
this._hideAllTimeout = setTimeout(() => Progress.hideAll(),800);
}
componentWillUnmount() {
clearTimeout(this._hideAllTimeout);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question