I need to stop the flicker that happens on loading a React component with an SVG inside, so that the SVG appears offscreen at the start. I'm using React Hooks and a simple setTimeOut inside a useEffect hook to control a display property does not seem to work.
This animation code works, but produces a flicker:
const mortarBoard = useRef(null);
useEffect(() => {
const tl = new TimelineMax();
tl.fromTo("#mortarboard", 5, { y: 1200 }, { y: 0 });
}, []);
whereas this code the flicker is not noticeable:
const mortarBoard = useRef(null);
useEffect(() => {
TweenMax.fromTo(
[mortarBoard.current],
0.5,
{ x: 5, y: 18 },
{ x: -5, y: -40, yoyo: true, repeat: 3 }
);
}, []);
How do I hide the component before the animation starts?