Git Product home page Git Product logo

Comments (3)

skt-t1-byungi avatar skt-t1-byungi commented on May 26, 2024 1

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.

abhijithvijayan avatar abhijithvijayan commented on May 26, 2024

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.

skt-t1-byungi avatar skt-t1-byungi commented on May 26, 2024

Okay, I supplemented the readme as your advice.

from rsup-progress.

Related Issues (4)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.