Created
July 27, 2022 17:51
-
-
Save hwkr/3fdea5d7f609b98c162e5325637cf3cb to your computer and use it in GitHub Desktop.
Auto Animate Component
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { ElementType, HTMLAttributes } from "react"; | |
import { useAutoAnimate } from "@formkit/auto-animate/react"; | |
interface Props extends HTMLAttributes<HTMLElement> { | |
as?: ElementType; | |
} | |
export const AutoAnimate: React.FC<Props> = ({ | |
as: Tag = "div", | |
children, | |
...rest | |
}) => { | |
const [ref] = useAutoAnimate<HTMLElement>(); | |
return ( | |
<Tag ref={ref} {...rest}> | |
{children} | |
</Tag> | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment