Skip to content

Commit

Permalink
Merge pull request #129 from limxingzhi/fix/119/unnecessary-renders
Browse files Browse the repository at this point in the history
fix: optimized react for unnecessary renders
  • Loading branch information
justin-schroeder committed Sep 5, 2023
2 parents 5a4cb34 + 388d037 commit c8d2202
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/react/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,17 @@ export function useAutoAnimate<T extends Element>(
if (node instanceof HTMLElement) {
setController(autoAnimate(node, options))
} else {
setController(undefined);
setController(undefined)
}
}, [])
const setEnabled = (enabled: boolean) => {
if (controller) {
enabled ? controller.enable() : controller.disable()
}
}
}, [options])
const setEnabled = useCallback(
(enabled: boolean) => {
if (controller) {
enabled ? controller.enable() : controller.disable()
}
},
[controller]
)

return [element, setEnabled]
}

1 comment on commit c8d2202

@vercel
Copy link

@vercel vercel bot commented on c8d2202 Sep 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.