Comments (3)
If the start and end periods are short, progress does not appear. If you need a minimum animation, there is also a solution below.
useEffect(() => {
const progress = new Progress();
let pMin = null
Router.events.on('routeChangeStart', () => {
progress.start()
pMin = new Promise(r => setTimeout(r, 100)) // <= `100` is minimun animation time
});
Router.events.on('routeChangeComplete', () => {
return pMin.then(() => progress.end());
});
Router.events.on('routeChangeError', () => {
return pMin.then(() => progress.end());
});
}, []);
(The animation starts at the next frame after calling the start function. If the end is called before that, it should not appear.)
from rsup-progress.
Thanks. it works.
For anyone who stumbles across this, here is the typescript version
useEffect((): void => {
const progressBar: Progress = new Progress();
let timer: null | Promise<any> = null;
Router.events.on('routeChangeStart', (): void => {
progressBar.start();
timer = new Promise((resolve) => {
return setTimeout(resolve, 100);
});
});
Router.events.on('routeChangeComplete', (): void => {
if (timer) {
// wait for promise to resolve(ensures min 100ms animation)
timer.then((): undefined => {
return progressBar.end();
});
}
});
Router.events.on('routeChangeError', (): void => {
if (timer) {
timer.then((): undefined => {
return progressBar.end();
});
}
});
}, []);
from rsup-progress.
Okay, I supplemented the readme as your advice.
from rsup-progress.
Related Issues (4)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rsup-progress.