Skip to content

Instantly share code, notes, and snippets.

@hwkr
Created July 27, 2022 17:51
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save hwkr/3fdea5d7f609b98c162e5325637cf3cb to your computer and use it in GitHub Desktop.
Save hwkr/3fdea5d7f609b98c162e5325637cf3cb 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