We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
useFlip
We can use gsap Flip to animate an element between states.
useFlip(ref, { duration: 0.6, delay: 0.3, });
import { useIsomorphicLayoutEffect, unref, Unreffable } from '@mediamonks/react-hooks'; import gsap from 'gsap'; import Flip from 'gsap/Flip'; import { useMemo, useRef, type MutableRefObject } from 'react'; gsap.registerPlugin(Flip); export function useFlip( ref: Unreffable<HTMLElement | null>, flipStateVariables: Flip.FromToVars = {}, ): MutableRefObject<Flip.FlipState | undefined> { const flipStateRef = useRef<Flip.FlipState>(); const memoizedFlipStateVariables = useMemo( () => flipStateVariables, // eslint-disable-next-line react-hooks/exhaustive-deps Object.values(flipStateVariables), ); if (typeof window !== 'undefined') { flipStateRef.current = Flip.getState(unref(ref)); } useIsomorphicLayoutEffect(() => { if (flipStateRef.current === undefined) { return; } Flip.from(flipStateRef.current, { ...memoizedFlipStateVariables, }); }); return flipStateRef; }
The text was updated successfully, but these errors were encountered:
Create useFlip hook #183
bae0edc
No branches or pull requests
We can use gsap Flip to animate an element between states.
The text was updated successfully, but these errors were encountered: