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

Nextjs Dyncamic import animation doesn't work? #24

Closed
gsambrotta opened this issue Dec 28, 2020 · 1 comment
Closed

Nextjs Dyncamic import animation doesn't work? #24

gsambrotta opened this issue Dec 28, 2020 · 1 comment

Comments

@gsambrotta
Copy link

Hi there, I'm using react-odometerjs in Nextjs.
As suggested by the doc, I import it with dynamic import but I this way the number don't animate when change.
Maybe is something else but if I import it without dynamic import, I can see the number animate just before the next render when I get the error "document not defined".

Anyone else having this issue?

@gsambrotta
Copy link
Author

To make the animation works we just need to implement also the clean up function, which is anyway a best practice!

useEffect(() => {
    setOdometerValue(300);
    const interval = setInterval(() => {
      setOdometerValue((value) => value + 300);
    }, 20000);
    
    return () => clearInterval(interval);
}, []);

Hope this helps others!

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

No branches or pull requests

1 participant