Skip to content

Commit

Permalink
Fix Max update depth exceeded with useAutoAnimate
Browse files Browse the repository at this point in the history
  • Loading branch information
GeraOSF committed Nov 3, 2023
1 parent 8e4626a commit 3cd8cae
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/react/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState, useCallback, RefCallback } from "react"
import { useState, useCallback, RefCallback, useMemo } from "react"
import autoAnimate, {
AutoAnimateOptions,
AutoAnimationPlugin,
Expand All @@ -16,15 +16,16 @@ export function useAutoAnimate<T extends Element>(
const [controller, setController] = useState<
AnimationController | undefined
>()
const memoizedOptions = useMemo(() => options, [])
const element = useCallback(
(node: T) => {
if (node instanceof HTMLElement) {
setController(autoAnimate(node, options))
setController(autoAnimate(node, memoizedOptions))
} else {
setController(undefined)
}
},
[options]
[memoizedOptions]
)
const setEnabled = useCallback(
(enabled: boolean) => {
Expand Down

0 comments on commit 3cd8cae

Please sign in to comment.