Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

react-countup fails to work in next.js produnction environment #822

Open
liuyangjason opened this issue Nov 13, 2023 · 5 comments · May be fixed by #874
Open

react-countup fails to work in next.js produnction environment #822

liuyangjason opened this issue Nov 13, 2023 · 5 comments · May be fixed by #874

Comments

@liuyangjason
Copy link

i use react-countup (version 6.5.0) in a page router based next.js application.

when i run pnpm dev, react-countup works well and the number increases to the target value.

when i run 'pnpm start', react-countup fails to work and the number keeps to be zero.

@liuyangjason
Copy link
Author

liuyangjason commented Nov 13, 2023

there is a workaround.

Code fails to work in nextjs production mode

         <CountUp
                  start={0}
                  end={10}
                  duration={2.75}
                  separator=" "
                  decimals={0}
                  decimal=","
                  prefix=""
                  suffix=" +"
                >
                  {({ countUpRef }) => (
                    <div>
                      <span ref={countUpRef} />
                    </div>
                  )}
         </CountUp>

Code works in next.js production mode

       <CountUp
                  start={0}
                  end={10}
                  duration={2.75}
                  separator=" "
                  decimals={0}
                  decimal=","
                  prefix=""
                  suffix=" +"
     />

@agyarg
Copy link

agyarg commented Nov 22, 2023

+1 mine too!

edit: nevermind. i found the solution and explanation:

image

just add "delay=0":

 <CountUp
              start={0}
              end={count.number}
              duration={3}
              separator="."
              decimal="."
              suffix="+"
              delay={0}
            >
              {({ countUpRef }) => <h4 className="" ref={countUpRef} />}
</CountUp>

and it worked.

@AbhayaShankar
Copy link

AbhayaShankar commented Nov 30, 2023

Does anyone have any idea what if I wanted to render the counter with a delay ?
I was using with delay of {1} , and it didn't work in prod

@kimiiz55
Copy link

work for me

Currently react-countup is having issues with the enableScrollSpy. A simple work around is to install react-visibility-sensor and use like below.

import VisibilitySensor from 'react-visibility-sensor';

  <CountUp end={400}>
    {({ countUpRef, start }) => (
      <VisibilitySensor onChange={start}>
        <span ref={countUpRef} />
      </VisibilitySensor>
    )}
  </CountUp>

ref: https://stackoverflow.com/questions/73210108/problem-with-react-countup-enablescrollspy

@denandserg
Copy link

Confirm that the dev bundle and prod bundle works in a little bit different way. Issue is still actual for production mode. React, Vite bundler

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants