auto-animate: Maximum update depth exceeded on 8.0.0
Getting the following error in V8.0.0
Error: Maximum update depth exceeded. This can happen when a component repeatedly calls setState inside componentWillUpdate or componentDidUpdate. React limits the number of nested updates to prevent infinite loops.
Running on NextJS
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 3
- Comments: 19 (8 by maintainers)
Commits related to this issue
- fix(#166): Maximum update depth exceeded on 8.0.0 — committed to IvarssonAndreas/auto-animate by IvarssonAndreas 3 years ago
- fix: memoize options in react (#166) Fix Max update depth exceeded with useAutoAnimate — committed to formkit/auto-animate by justin-schroeder 3 years ago
Memoizing the optional configuration (or making the object reference constant) seems to fix the issue on my end.
Just wanted to mention I’m getting this too when trying to add an optional plugin. Doesn’t occur when using plain
useAutoAnimate().react: 18.2.0 next: 12.2.0 autoAnimate: ^0.8.0
Edit: @justin-schroeder Updated with stackblitz showing the error. (link)
I am not completely sure that the merged fix represents the intended behaviour.
With the new change, it will no longer be possible to systematically update the options used by autoAnimate, and only the options set when the component was mounted using useAutoAnimate will always be used.
Maybe these are niche cases, but it becomes impossible[^1] to change the easing or the duration systematically.
[^1]: or very complicated and counterintuitive as one would have to remount the component using useAutoAnimate by manually changing the key
This fix is now published in 0.8.1
@verheyenkoen You might already know this, but figured I’d post this in case someone else needed this bug fix before their next release. You can choose to install the library from the master branch of this repository instead of a release version. Run the following command. It will install build and install @formkit/auto-animate from the specified branch. If you already have @formkit/auto-animate in your package.json that’s fine, it’ll update it to point to this master branch.
npm i formkit/auto-animate#masterI believe this should work with yarn and pnpm as well.
Note: Notice I didn’t type
npm i @formkit/auto-animate#aster, there’s no @ namespace before formkit. This is because npm will search for the formkit/auto-animate repository, not the @formkit npmjs namespace.I think it has to do with the optional configuration. this gives me error:
const [parent] = useAutoAnimate({ duration: 150 })and not this:const [parent] = useAutoAnimate()