import React, { useRef, useCallback, useEffect, Fragment, useState } from 'https://cdn.skypack.dev/react@17.0.1'; import { render } from 'https://cdn.skypack.dev/react-dom@17.0.1'; const animejs = anime; function Anime(props: AnimeProps) { // Current anime instance const animes = useRef([]); // Currently fed Anime targets const targets = useRef([]); //Current refs const targetRefs = useRef([]); // Completed Anime targets const completed = useRef(new Set()); const cycleAnime = props => { // 🗾 Reset Anime.js for (let ani of animes.current) { if (ani.completed) animes.current = animes.current.filter(a => a != ani); } if (targets.current.length > 0) animejs.remove(targets); targets.current = []; // ➕ Add new target references that haven't completed for (let ref of targetRefs.current) { if (ref.current && !completed.current.has(ref.current)) targets.current.push(ref.current); } // 😮 Overload complete callback const complete = (ani: AnimeInstance) => { if (props.complete) props.complete(ani); ani.animatables.map((a: any) => completed.current.add(a.target)); }; const animeProps: any = { ...props, targets: targets.current, complete }; delete animeProps.children; delete animeProps.svg; animes.current.push(animejs(animeProps)); }; const createAnime = useCallback(() => { cycleAnime(props); }, [props]); useEffect(() => { createAnime(); }, [createAnime]); const refs = targetRefs.current; /* istanbul ignore next */ let children: ReactNodeArray = Array.isArray(props.children) ? props.children : [props.children]; return ( {children.flat().map((child: any, i: number) => { refs.push(React.createRef()); /* istanbul ignore next */ const El = props.component ? props.component : 'div'; return ( {child} ); })} ); } function App(props) { let [state, setState] = useState({ myList: ['First Entry'] }); return ( ); } const node = document.getElementById('app'); render(, node);