Skip to content

Instantly share code, notes, and snippets.

@mikowl
Forked from hwkr/auto-animate.tsx
Created August 4, 2022 22:38
Show Gist options
  • Save mikowl/4c2a765f6194f5eb3c9ccbeb5bca14d5 to your computer and use it in GitHub Desktop.
Save mikowl/4c2a765f6194f5eb3c9ccbeb5bca14d5 to your computer and use it in GitHub Desktop.
Auto Animate Component
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