import React from 'react'; import {useFirstPaint} from './useFirstPaint'; import './_use-first-paint-example.scss'; import classNames from 'classnames'; export const Example = () => { const animatedElementRef = React.useRef(); const shouldAnimateRef = React.useRef(false); const [isToggled, setIsToggled] = React.useState(true); const handleClick = React.useCallback(() => { setIsToggled(!isToggled); if (shouldAnimateRef.current) { // @ts-ignore TS18048 animatedElementRef.current.style.animationDuration = ''; } }, [isToggled]); React.useLayoutEffect(() => { // @ts-ignore TS18048 animatedElementRef.current.style.animationDuration = '0ms'; }, []); useFirstPaint(() => { shouldAnimateRef.current = true; }); return (
Click me
); };